Since this is not an obvious idiom. Here is a sample for lurkers.
sealed class MyEnum
{
*** private String name;
*** private static int nextOrdinal= 1;
*** private int ordinal= nextOrdinal++;
*** private MyEnum(String name)
*** {
******* this.name= name;
*** }
*** public override String ToString()
*** {
******* return name;
*** }
*** public int ToOrdinal()
*** {
******* return ordinal;
*** }
*** public static MyEnum INVALID= new MyEnum("Invalid"); // ordinal 1
*** public static MyEnum OPENED= new MyEnum("Opened"); // ordinal 2
*** public static MyEnum CLOSED=new MyEnum("Closed"); // ordinal 3
*** /// <summary>
*** /// The main entry point for the application.
*** /// </summary>
*** [STAThread]
*** static void Main(string[] args)
*** {
******* //
******* // TODO: Add code to start application here
******* //
******* Console.WriteLine(MyEnum.OPENED.ToString());
******* Console.WriteLine(MyEnum.OPENED.ToOrdinal().ToStri ng());
******* Console.WriteLine(MyEnum.INVALID.ToString());
******* Console.WriteLine(MyEnum.INVALID.ToOrdinal().ToStr ing());
******* Console.WriteLine(MyEnum.CLOSED.ToString());
******* Console.WriteLine(MyEnum.CLOSED.ToOrdinal().ToStri ng());
******* Console.ReadLine();
*** }
}
Regards,
Jeff
If your constants were numeric, then you would still need to use
reflection to get the name
associated with the value.<
*** Sent via Developersdex
http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!