Welcome back.
Now that we have seen a bit about structs, let's take a look at enums before we continue knowing what
enums are will be quite important.
Moving on.
So let's make sure that we really know what they are.
All right let's see them.
An enum is basically a set of constants.
It's immutable and should be placed at the namespace level.
So it can be used by the whole library.
And well it's pretty much something like let's say we have days.
So there are only seven days in a week.
So we can create an enum called day and it will contain a Monday.
It will contain a Tuesday or Wednesday or Thursday, Friday, Saturday and Sunday.
So these are our days.
And that's an enum.
All right.
That's already it.
So now if we want to use the day enum then we would have its seven values that there are and they never
change, right?
So you only have those seven days.
So now let's create an enum de in our main method.
So I'm going to create de.
And I'm going to call it fr sending for Friday.
And that will be de dot.
And as you can see there are our values and they are also indexed.
So they dot Friday is equal to four Monday is equal to zero.
All right.
So let's say I'm using Friday.
So it starts at four.
It is the value of four.
Now let's create another day.
Let's say it's Sunday.
It's day dot s u.
Now let's create another day that I'm just going to call a and a will be Friday.
So day.fr.
And now let's use the console write Console.WriteLine to check if fr is equal to a.
So if Friday is equal to our a day and we can check that out.
And before we do so we should add a console dot read key.
Like that.
Now let's start it again.
And we see it says true.
And that is because this day has the value of Friday, and this day here has also the value of Friday.
We can also do something like just printing it onto the console, so we can just go ahead and say something
like day.mo standing for Monday.
Let's see what it prints onto the screen.
And we see true.
And it says Monday Mo.
So Monday gave us the Monday value.
So it just said something like Mo but it's just a representation as a string and we can go ahead and
get the integer value as well.
So CW, let's get the integer of day.mo of Monday.
And as you know that zero because it starts with zero.
So we get here true mo and zero because the first value is zero.
Then we have one, two and so forth.
Now a little challenge.
Create an enum with the months of the year.
So please go ahead and do that.
All right.
So we have enum month and we have January February March April, may June July August September, October,
November and December.
So this is another month.
And now we can access those values in the same way.
And we can not only access them in this class, but we can access them in the whole namespace, because
I created them outside of this class and generally in that namespace.
Now let's say we want this to start with one.
So we want January to be at one.
So let's just set the value of one.
And now let's write the value of our month.
So we're going to get month dot January.
Or let's say we want to see February now is actually two.
So I'm going to use an integer casting here.
So I'm going to cast that into an integer.
Let's see.
And we see February is two now.
And that is because we started the index at one.
Now let's see if we can change as well.
Like July let's say July should be now 12 because usually it would be seven the seventh month.
But let's say July is the 12th month.
So let's also print that onto the console.
So I'm gonna use the same line of code like here, but I'm going to replace February with July or actually
let's say August.
Let's see what August gives us.
And we see it's 13.
So we can reassign the index.
And it will keep on counting from that point on.
So you see June is equal to 6th July equal to 12th August equal to 13 and so forth.
So generally, the one thing to remember, enums are there to share a set of constants to keep a library
consistent.
So you can use them in all the different classes.
And they will always have the same value.
And you won't have to create the constant inside of the classes all the time.
Great.
That would be it for enums.
Let's get back to structs now.
See you there.