Please explain to me the following C# program, which I came across in MSDN help:
// enumFlags.cs
// Using the FlagsAttribute on enumerations.
using System;
[Flags]
public enum CarOptions
{
SunRoof = 0x01,
Spoiler = 0x02,
FogLights = 0x04,
TintedWindows = 0x08,
}
class FlagTest
{
static void Main()
{
CarOptions options = CarOptions.SunR oof | CarOptions.FogL ights;
Console.WriteLi ne(options);
Console.WriteLi ne((int)options );
}
}
Output:
SunRoof, FogLights
5
Comments:
Notice that if you remove FlagsAttribute, the example will output the following:
5
5
// enumFlags.cs
// Using the FlagsAttribute on enumerations.
using System;
[Flags]
public enum CarOptions
{
SunRoof = 0x01,
Spoiler = 0x02,
FogLights = 0x04,
TintedWindows = 0x08,
}
class FlagTest
{
static void Main()
{
CarOptions options = CarOptions.SunR oof | CarOptions.FogL ights;
Console.WriteLi ne(options);
Console.WriteLi ne((int)options );
}
}
Output:
SunRoof, FogLights
5
Comments:
Notice that if you remove FlagsAttribute, the example will output the following:
5
5
Comment