I have this enum:
[Flags]
public enum MyEnum
{
None = 0,
ProductOne = 1,
ProductTwo = 2,
AllProducts = ProductOne | ProductTwo
}
I want to get the names (is names the right way to reference these?) of each item in the object that is passed in. I have this method to do that.
private string[] MyMethod(MyEnum myEnum)
{
if (myEnum == MyEnum.AllProducts)
{
return new string[] { MyEnum.ProductOne.ToString(), MyEnum.ProductTwo.ToString() };
}
else if (myEnum == MyEnum.None)
{
return new string[0];
}
return new string[] { myEnum.ToString() };
}
My question is, is there a way to somehow iterate through the values in the bitwise enum (MyEnum.AllProducts)
and put them into a string array, compared to the way I'm doing above?
Thanks.