I have an enumeration:
public enum SomeEnum
{
A = 2,
B = 4,
C = 8
D = 16
}
SomeEnum e1 = SomeEnum.A | SomeEnum.B
Now I want to have a List of enum values, so e1 would be:
2, 4
So I have:
List<int> list = new List<int>();
foreach(SomeEnum se in Enum.GetValues(typeof(SomeEnum)))
{
if(.....)
{
list.Add( (int)se );
}
}
I need help with the if statement above.
Update
How can I build a list of ints representing the flags set in the enum e1?
Do you want to add the value if it’s in e1?
Then you can use the HasFlag method in .NET 4.
If you’re not using .net the equivilant is
e1 & se == seAlso by convention you should mark your enum with the FlagsAttribute and it should be in plural form (SomeEnums)