Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Enum [modified]

Enum [modified]

Scheduled Pinned Locked Moved ASP.NET
databasehelpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shapper
    wrote on last edited by
    #1

    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

    N 1 Reply Last reply
    0
    • S shapper

      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

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      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

      S 1 Reply Last reply
      0
      • N Not Active

        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

        S Offline
        S Offline
        shapper
        wrote on last edited by
        #3

        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

        N 1 Reply Last reply
        0
        • S shapper

          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

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          enum Colors { White, Red, Green } int x = 1; Colors color = (Colors)x; color.ToString() == "Red"


          only two letters away from being an asset

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups