I have an enum with flagsattribute called ModuleType and I want to be able to loop through it. I am currently turning it into a string, and looping through the results as follows:
ModuleType mt = ModuleType.Option1 | ModuleType.Option2 | ModuleType.Option3;
string e = mt.ToString().Split(',');
foreach(string s in e)
ModuleType m = (ModuleType)Enum.Parse(typeof(ModuleType),s.Trim());
// Do work
Can anyone recommend a better or more elegant way of looping through the enumerator without having to turn them into a string and then back to an enumerator again?