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. General Programming
  3. Visual Basic
  4. Looping enum elements?

Looping enum elements?

Scheduled Pinned Locked Moved Visual Basic
question
4 Posts 3 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.
  • M Offline
    M Offline
    matsnas
    wrote on last edited by
    #1

    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, 2006

    D J 2 Replies Last reply
    0
    • M matsnas

      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, 2006

      D Offline
      D Offline
      Duncan Edwards Jones
      wrote on last edited by
      #2

      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

      M 1 Reply Last reply
      0
      • M matsnas

        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, 2006

        J Offline
        J Offline
        J4amieC
        wrote on last edited by
        #3

        Yes, 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

        1 Reply Last reply
        0
        • D Duncan Edwards Jones

          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

          M Offline
          M Offline
          matsnas
          wrote on last edited by
          #4

          Thanks! Had to put the brackets in there but now it works like a charm! For each vSize as eSize in [Enum].GetValues(GetType(eSize))   DoStuff(vSize) Next

          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