S
shapper
Hello,
Is there a way to loop trough all enumeration values?
Thanks,
Miguel
Is there a way to loop trough all enumeration values?
Thanks,
Miguel
Hello,
Is there a way to loop trough all enumeration values?
Thanks,
Miguel
Hi,
Hello,
Is there a way to loop trough all enumeration values?
Thanks,
Miguel
Yes:
enum MyEnum
{
// ...
}
Then:
MyEnum[] allEnumValues = (MyEnum[]) Enum.GetValues( typeof( MyEnum ) );
Then you can loop using foreach.
HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Hi,
I used the following code:
Public Enum Roles
End Enum
' Loop through each roles enumeration name
For Each role As String In Roles.GetNames(GetType(Roles))
MyFunction(role)
Next
This is working if MyFunction is as follows:
Function MyFunction(ByVal role As String)
However, I would like to use something like:
Function MyFunction(ByVal role As Roles)
How can I make this work?
Thanks,
Miguel
enum MyEnum
{
// ...
}
Then:
MyEnum[] allEnumValues = (MyEnum[]) Enum.GetValues( typeof( MyEnum ) );
Then you can loop using foreach.
I used the following code:
Public Enum Roles
End Enum
' Loop through each roles enumeration name
For Each role As String In Roles.GetNames(GetType(Roles))
MyFunction(role)
Next
This is working if MyFunction is as follows:
Function MyFunction(ByVal role As String)
However, I would like to use something like:
Function MyFunction(ByVal role As Roles)