Reputation: 137
i declare enum
enum Month
{
January , February , March , April , May , June , July ,
Augest , September , Octobre , November , December
}
then in the main prog
static void DoWork()
{
// to do
Month first = Month.January;
Console.WriteLine("First Month of the Year : {0}", first);
first++;
Console.WriteLine((int)first);
}
the output on the seond line should 2
but what i get actually is 1
what is the problem is that ( pass by value issue or somthing else )
Upvotes: 2
Views: 47
Reputation: 37020
By default, the first item in an enum is '0', with each item incrementing by 1
. You can assign values manually, however, and that should fix the issue for you.
Note that, in your case, just setting the first item to 1
should do the trick, but you can specify a value for any and all of them:
enum Month
{
January = 1, February , March , April , May , June , July ,
Augest , September , Octobre , November , December
}
Upvotes: 3