‫Welcome back.
‫Now that you know how to create variables, it's time to have a look at immutable values, which are
‫called constants.
‫So we are going to create variables which are not changeable after they have been created.
‫So the means after the compile time has started, they cannot be changed for the lifetime of the program.
‫And that's a very useful tool because there are some variables which you just don't want them to ever
‫change.
‫For example, pie, you don't want pie to ever change, it will always be the same or general.
‫There are variables which you just don't want to change and we are going to create some of those.
‫So let's create them and go ahead right here before our main method.
‫So the idea behind constants is that they usually are fields, so variables which are outside of any
‫method, so which are in the class, but outside of any method.
‫So the means we create fields now which are constants, so constants as fields.
‫And in order to create constants you need the const keyword and then you indicate which data type you
‫want.
‫So in my case, let's say I want to have a double which I call pie, and that value should always be
‫3.14159265359.
‫So that's a pretty precise pie.
‫And you can now go ahead and calculate, for example, everything that is surrounding circles with that
‫variable pie.
‫Then for example, a constant which is of type int and will be weeks because there are only a certain
‫amount of weeks in a year.
‫So let's say we want to save that as a variable and which is a field, a constant field.
‫And then I want to at the same time store the months as there are only 12 months in a year.
‫So you can simply do that within one row just like that or within one line, just like that.
‫And you could go ahead and say, okay, there are 365 days in a year, but then there are different
‫years and some years there are 366 days.
‫And that's why it's tricky to use days as a constant.
‫So let's say we set that up as 365 and now every four years we would like to change that.
‫We'd like to set days as being 366 days.
‫And now you see the left hand side of an assignment must be a variable property or indexer.
‫So it says we cannot change that days constant as it's constant.
‫So it's immutable, as I stated right here.
‫All right.
‫So don't do that.
‫Don't try to change constants.
‫And by the way, let's get rid of this days constant because it's pretty tricky, as I said.
‫Now for you, a little challenge create a constant as a field, which is your birthday as a string.
‫So go ahead and create a constant of type string with your birthday as its value.
‫All right.
‫I hope you tried it.
‫So, concert string and I'm going to call that birthday and it's going to be a string.
‫So I need to parentheses.
‫And here I enter 31st of May in 1988.
‫So now this is the structure that we have in Germany.
‫This is how we apply dates, all we write dates.
‫Of course, it could be a different one, so I'm going to copy that.
‫In your case, based on the country you're at, you have different standards.
‫So maybe you have the month first and then you have the day or even further.
‫Let's go ahead and use something like even the year first, then the month and then the day like that.
‫So there are different ways of writing a birthday.
‫I know that.
‫So either one is fine.
‫The important thing is that you created a constant and you created a string field, which is a birthday
‫field, and now you can simply print out your birthday.
‫So please go ahead and try that.
‫So see w double tab gives me the console right line and I'm here, I'm going to enter.
‫My birthday is always going to be and then here I use the curly brackets and the zero in order to add
‫a variable afterwards.
‫So I'm going to add a variable at that position here at the zero position, which is going to be my
‫birthday constant.
‫All right.
‫So now let's run that for that.
‫We need to console the read key, for example, so that our application doesn't stop.
‫And we are.
‫My birthday is always going to be the 31st of May 1988.
‫Okey dokey.
‫So now that you know how to create constants and how to use them, please go ahead with the next video.
‫And keep in mind, simply use the const keyword before the data type whenever you want to use constants.