If you apply the [Flags]
attribute to the enum, it will make the enum's ToString()
return a string which indicates which bits are set - but I don't think that is going to be that useful to you, other than its role in documenting that the enum is a flags enum.
However, regardless of the presence of the [Flags]
attribute, Enum.HasFlag()
will tell you if the flag is set.
This sample console app should make it clear:
using System;
namespace Demo
{
[Flags]
enum Status
{
None = 0,
Status1 = 1,
Status2 = 2,
Status3 = 4,
Status4 = 8,
Status5 = 16,
Status6 = 32,
Status7 = 64,
Status8 = 128,
Status9 = 256,
Status10 = 512,
Status11 = 1024
}
class Program
{
static void Main()
{
Status s = (Status)1035;
Console.WriteLine(s); // "Status1, Status2, Status4, Status11"
if (s.HasFlag(Status.Status4)) // "Status 4 is set"
Console.WriteLine("Status4 is set");
else
Console.WriteLine("Status4 is not set");
if (s.HasFlag(Status.Status3)) // "Status 3 is not set"
Console.WriteLine("Status3 is set");
else
Console.WriteLine("Status3 is not set");
}
}
}
Note: Your enum appears to be missing some values! The 1024 value should be Status11, not Status8.
Also note that I added a "None" value for completeness.