C# Enum Question

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

    C# Enum Question

    What is the best method to convert an integer to Enum equivelant?

    I hope this makes sense.

    Thanks,

    David


  • Hans Kesting

    #2
    Re: C# Enum Question

    Yosh wrote:[color=blue]
    > What is the best method to convert an integer to Enum equivelant?
    >
    > I hope this makes sense.
    >
    > Thanks,
    >
    > David[/color]

    cast:

    MyEnum enumvar = (MyEnum)intvar;


    Hans Kesting


    Comment

    • Mythran

      #3
      Re: C# Enum Question


      "Yosh" <Yosh@nospam.co m> wrote in message
      news:%23kWPW70R FHA.1564@TK2MSF TNGP09.phx.gbl. ..[color=blue]
      > What is the best method to convert an integer to Enum equivelant?
      >
      > I hope this makes sense.
      >
      > Thanks,
      >
      > David
      >[/color]

      // Notice the type specifier, int.
      public enum MyEnums : int
      {
      Enum1 = 0,
      Enum2,
      Enum3
      }


      ...

      MyEnum myVar = 1;

      ...

      Another way:

      MyEnum myVar = (MyEnums) 1;

      ...

      If you just have the name of the enum value:

      MyEnum myVar = System.Enum.Par se(typeof(MyEnu ms), "Enum2");

      Hope this helps ;)

      Mythran

      Comment

      Working...