Looping enum elements?
-
Hi! Can you loop enum elements? Ex:
public enum eSize Small Medium Large end enum For each vSize as eSize in eSize.Elements DoStuff(vSize) next
-- modified at 8:40 Monday 9th January, 2006You could use the Enum class' .GetValues shared function..
For each vSize as eSize in Enum.GetValues(GetType(eSize)) DoStuff(vSize) Next
'--8<------------------------ Ex Datis: Duncan Jones Merrion Computing Ltd -
Hi! Can you loop enum elements? Ex:
public enum eSize Small Medium Large end enum For each vSize as eSize in eSize.Elements DoStuff(vSize) next
-- modified at 8:40 Monday 9th January, 2006Yes, you use the static methods defined in the
Enum
class Heres some test code for you. The button on my test for was button3 enum MyEnum { Foo, Bar, Laa, Noe } private void button3_Click(object sender, System.EventArgs e) { string [] names = Enum.GetNames(typeof(MyEnum)); MyEnum[] enums = (MyEnum[])Enum.GetValues(typeof(MyEnum)); for(int i=0;i -
You could use the Enum class' .GetValues shared function..
For each vSize as eSize in Enum.GetValues(GetType(eSize)) DoStuff(vSize) Next
'--8<------------------------ Ex Datis: Duncan Jones Merrion Computing Ltd