Enum [modified]
-
Hello, I have an enum: Public Enum Color Red Blue Green End Enum I need: 1. Loop trough all enum items and get each one value (Ex: Red) and index (Ex: 1). For Each color As Color In [Enum].GetValues(GetType(Color)) ??? Next 2. Get an enum value (Ex: Red) by providing its index (Ex: 1) I tried various options but I am not able to make this work. Thank you for your Help, Miguel -- modified at 15:05 Friday 12th January, 2007
-
Hello, I have an enum: Public Enum Color Red Blue Green End Enum I need: 1. Loop trough all enum items and get each one value (Ex: Red) and index (Ex: 1). For Each color As Color In [Enum].GetValues(GetType(Color)) ??? Next 2. Get an enum value (Ex: Red) by providing its index (Ex: 1) I tried various options but I am not able to make this work. Thank you for your Help, Miguel -- modified at 15:05 Friday 12th January, 2007
So what have you tried? Do you get any exception or are the values not what you are expecting?
only two letters away from being an asset
-
So what have you tried? Do you get any exception or are the values not what you are expecting?
only two letters away from being an asset
Hello, I have the following: ' Loop through each color enumeration name For Each color As Color In [Enum].GetNames(GetType(Color)) Dim name As String = MyF(color, Thread.CurrentThread.CurrentCulture) Dim index As Integer = CType(color, Enumeration.District) Response.Write("Name: " & name & " | Index: " & index.ToString & "
") Next I think this is working but I am not sure if this is the best way to solve this. Note: MyF is a function with a Select Case block which returns a string giving a enum element and a culture. I need this. However, I now need to get the text of an element by giving its index. For example, get "Red" when I say 1. Could someone help me out? Thanks, Miguel -
Hello, I have the following: ' Loop through each color enumeration name For Each color As Color In [Enum].GetNames(GetType(Color)) Dim name As String = MyF(color, Thread.CurrentThread.CurrentCulture) Dim index As Integer = CType(color, Enumeration.District) Response.Write("Name: " & name & " | Index: " & index.ToString & "
") Next I think this is working but I am not sure if this is the best way to solve this. Note: MyF is a function with a Select Case block which returns a string giving a enum element and a culture. I need this. However, I now need to get the text of an element by giving its index. For example, get "Red" when I say 1. Could someone help me out? Thanks, Miguelenum Colors { White, Red, Green } int x = 1; Colors color = (Colors)x; color.ToString() == "Red"
only two letters away from being an asset