Hi,
I found the cause.
Its very funny...
In your case
public enum Weekdays
{
Sunday,
Monday=Sunday,
Tuesday,
Wednesday=Sunday,
Thursday,
Friday,
Saturday
}
Few rule :
1. If you don't set any value to enum it will set incrementally by order of it.(0...)
2. Enum is a value type
3. Microsoft's recommendation always set a value to enum don't place it without a value.
We will discusses about few things which may irrelevant to real world but those very important to know for good developers.
You set 3 enum with same value and you did not set Sunday also
so Sunday =0
set Monday =Sunday (mean Monday is also 0)
set Wednesday = Sunday (mean Wednesday is also 0)
in this case .Net will pick the First one in which order they added to Enum
in your case
Sunday
Monday
Wednesday
any of above enum will print
Sunday. Sunday is register with value 0 at first and you refer the same.
Sunday=0
Monday=0
Wednesday=0
Now if you just set value 0 to all of them (Sunday,Monday and Wednesday) it will show Wednesday because its set to value and all value are same to compiler pick last one.
If you refer or set from another enum it will pick the 1st reference value (if same dose not exists)
Another case:
I don't whether you test other enum's if you then you will find
Tuesday and Thursday it will always show Thursday because
see how compiler will define those values
Sunday=0,
Monday=0,
Tuesday=1,
Wednesday=0,
Thursday=1,
Friday=2,
Saturday=3
Ok now compile will show the last one in order which they added in enum.
So it will show
Thursday
No to check the same just alternate the position of Tuesday and Thursday
then it will return
Tuesday
Another Case :
public enum Weekdays
{
Sunday,
Monday = Sunday,
Tuesday = Monday,
Wednesday = Tuesday,
Thursday = Wednesday,
Friday = Thursday,
Saturday = Friday
}
Now it will print
Wednesday
In this scenario .net will pick the middle one. as there were 7 item it will pick 4th if there 6 item it will pick 3 :)
Conclusion always set some value against enum.
Enjoy...