recurse through members of an enum

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Laszlo Szijarto

    recurse through members of an enum

    What's the best way to recurse through the members of an enum?

    I want to take an enum and dump into a ListBox the enum's names.

    Thank you,
    Laszlo


  • William Stacey

    #2
    Re: recurse through members of an enum

    Console.WriteLi ne("The values of the Colors Enum are:");
    foreach(string s in Enum.GetNames(t ypeof(Colors)))
    Console.WriteLi ne(s);

    --
    William Stacey, DNS MVP

    "Laszlo Szijarto" <lszijarto@nosp am.mrdoc.cc> wrote in message
    news:bm1pl7$muh $1@sulawesi-fi.lerc.nasa.go v...[color=blue]
    > What's the best way to recurse through the members of an enum?
    >
    > I want to take an enum and dump into a ListBox the enum's names.
    >
    > Thank you,
    > Laszlo
    >
    >[/color]


    Comment

    • Alvin Bruney

      #3
      Re: recurse through members of an enum

      I don't think this is possible since an enum is a type. You can iterate thru
      collections which implement ienumerable, but an enum is not a collection.

      "Laszlo Szijarto" <lszijarto@nosp am.mrdoc.cc> wrote in message
      news:bm1pl7$muh $1@sulawesi-fi.lerc.nasa.go v...[color=blue]
      > What's the best way to recurse through the members of an enum?
      >
      > I want to take an enum and dump into a ListBox the enum's names.
      >
      > Thank you,
      > Laszlo
      >
      >[/color]


      Comment

      • Michael Bray

        #4
        Re: recurse through members of an enum

        "Alvin Bruney" <vapordan_spam_ me_not@hotmail_ no_spamhotmail. com> wrote
        in news:uLYIhSgjDH A.2772@TK2MSFTN GP12.phx.gbl:
        [color=blue]
        > I don't think this is possible since an enum is a type. You can
        > iterate thru collections which implement ienumerable, but an enum is
        > not a collection.[/color]

        You can do this type of operation with Reflection... see previous post
        replies for some specific code that demonstrates it.

        -mbray

        Comment

        • Alvin Bruney

          #5
          Re: recurse through members of an enum

          Thanks
          "Michael Bray" <mbrayXXnoSPAMp leaseXX@SkPiAlM l.ctiusa.com> wrote in message
          news:Xns940EEE0 1C5046mbrayxyzc tiusacom@207.46 .248.16...[color=blue]
          > "Alvin Bruney" <vapordan_spam_ me_not@hotmail_ no_spamhotmail. com> wrote
          > in news:uLYIhSgjDH A.2772@TK2MSFTN GP12.phx.gbl:
          >[color=green]
          > > I don't think this is possible since an enum is a type. You can
          > > iterate thru collections which implement ienumerable, but an enum is
          > > not a collection.[/color]
          >
          > You can do this type of operation with Reflection... see previous post
          > replies for some specific code that demonstrates it.
          >
          > -mbray[/color]


          Comment

          • Alvin Bruney

            #6
            Re: recurse through members of an enum

            sweet code william. sweet code
            "William Stacey" <staceyw@mvps.o rg> wrote in message
            news:uUkB0RgjDH A.1656@tk2msftn gp13.phx.gbl...[color=blue]
            > Console.WriteLi ne("The values of the Colors Enum are:");
            > foreach(string s in Enum.GetNames(t ypeof(Colors)))
            > Console.WriteLi ne(s);
            >
            > --
            > William Stacey, DNS MVP
            >
            > "Laszlo Szijarto" <lszijarto@nosp am.mrdoc.cc> wrote in message
            > news:bm1pl7$muh $1@sulawesi-fi.lerc.nasa.go v...[color=green]
            > > What's the best way to recurse through the members of an enum?
            > >
            > > I want to take an enum and dump into a ListBox the enum's names.
            > >
            > > Thank you,
            > > Laszlo
            > >
            > >[/color]
            >
            >[/color]


            Comment

            • Laszlo Szijarto

              #7
              Re: recurse through members of an enum

              Thank you. This is what I needed. Thank you all for your replies.


              "William Stacey" <staceyw@mvps.o rg> wrote in message
              news:uUkB0RgjDH A.1656@tk2msftn gp13.phx.gbl...[color=blue]
              > Console.WriteLi ne("The values of the Colors Enum are:");
              > foreach(string s in Enum.GetNames(t ypeof(Colors)))
              > Console.WriteLi ne(s);
              >
              > --
              > William Stacey, DNS MVP
              >
              > "Laszlo Szijarto" <lszijarto@nosp am.mrdoc.cc> wrote in message
              > news:bm1pl7$muh $1@sulawesi-fi.lerc.nasa.go v...[color=green]
              > > What's the best way to recurse through the members of an enum?
              > >
              > > I want to take an enum and dump into a ListBox the enum's names.
              > >
              > > Thank you,
              > > Laszlo
              > >
              > >[/color]
              >
              >[/color]


              Comment

              Working...