Thanks Mats,
1.
I have written a test program which shows whether or not using Flags attribute, the result value is the same, the presentation form is different when using Console.write method.
Code:
enum e1 { a,b,c,d};
[Flags]
enum e2 { a, b, c, d };
static void Main(string[] args)
{
e1 MyE1 = e1.a | e1.b;
e2 MyE2 = e2.a | e2.b;
// e1 == e2
return;
}
So, the conclusion is, value the same, but presentation form is differnet? Right?
2.
If yes, besides Console.write, any other presentation forms which will show the differences when using Flags attribute or not?
Originally Posted by
matsp
Essentially, it converts the enum to be have bit values instead of single values. If you or together SunRoof and FogLights, the value is 5, and in normal mode, that isn't part of the enum value range, so the decimal value 5 is printed. In FlagsAttribute mode, it splits out the bits of the enum and shows the SunRoof and FogLights as separate units.
--
Mats
I do not agree, Magos! :-)
It is ok to me. Could you show your complete test code please?
Originally Posted by
Magos
Nope, you can't. You could however do Days d = (Days)1234; with an exception being thrown if 1234 has no mathing value in Days.
regards,
George