Re: Smart way to connect enums to string values
From: Štefan Šimek (simek.blah_at_kascomp.blah.sk)
Date: 10/12/04
- Next message: John Wood: "Re: wizard like application"
- Previous message: Gas: "Re: Character representation"
- In reply to: Henke: "Smart way to connect enums to string values"
- Next in thread: Henke: "Re: Smart way to connect enums to string values"
- Reply: Henke: "Re: Smart way to connect enums to string values"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 12 Oct 2004 15:45:45 +0200
"Henke" <henke_nord@hotmail.com> wrote in message
news:e4i7HBGsEHA.3980@TK2MSFTNGP12.phx.gbl...
> Hi!
> Has anyone a nice way to connect a enum to a string value.
> Now I declare a const string [] in the same class as my enum is defined.
> But I doubt that's the "object oriented" way of doing it.
> Any better suggestions?
>
> Thanks in advance?
> /Henke
>
I don't know if I understand your question well, but you might like to have
a look at the
Enum.ToString() and Enum.Parse() functions, like:
enum Test { One, Two, Three };
public static void Main(string[] args)
{
Test tst = Test.One;
string str = tst.ToString();
Test tst2 = (Test) Enum.Parse(typeof(Test), str);
Console.WriteLine("tst = {0}\nstr = {1}\ntst2 = {2}", tst, str, tst2);
}
HTH,
Stefan
- Next message: John Wood: "Re: wizard like application"
- Previous message: Gas: "Re: Character representation"
- In reply to: Henke: "Smart way to connect enums to string values"
- Next in thread: Henke: "Re: Smart way to connect enums to string values"
- Reply: Henke: "Re: Smart way to connect enums to string values"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|