![]() |
| | #1 |
| Registered User Join Date: Oct 2008
Posts: 85
| Enum problem i have an enum Code:
public class1
{
public enum types
{
car=1,
bike =3,
trailer=5,
lorry = 11
}
}
Code: int value = 5; textbox1.text = ???? <----- get the word 'trailer' to go to text box please would i be better with a switch/case statement ? thanks |
| deviousdexter is offline | |
| | #2 |
| Registered User Join Date: Jun 2008 Location: RING 0
Posts: 468
| You should use a hashtable if you want to do something like that (dictionary in C#). Otherwise just make an enum of type types (in your case), assign it one of its respective enum values, and then call toString(). |
| valaris is offline | |
| | #3 |
| Confused Join Date: Sep 2001 Location: Sweden
Posts: 3,125
| Code: enum MyEnum { One, Two, Three }
System.Enum.GetName(typeof(MyEnum), MyEnum.Two);
__________________ MagosX.com Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime. |
| Magos is offline | |
| | #4 |
| Registered User Join Date: Mar 2009 Location: england
Posts: 95
| Code: int value = 5; textBox1.Text = ((types)value).ToString(); // should be trailer |
| theoobe is offline | |
| | #5 |
| Registered User Join Date: May 2009
Posts: 1
| Code: static partial class Extenstions
{
static public string GetString(this Enum p_enum) {
return Enum.GetName(p_enum.GetType(), p_enum);
}
}
Code: Numbers k = Numbers.One; Console.WriteLine(k.GetString()); //One |
| fairweather is offline | |
| | #6 |
| Registered User Join Date: Oct 2008
Posts: 85
| Sorry i thought i had posted back to this thread, must have forgotten the submit button. both the Theoobe and Magos' solutions were tried and did what i needed - i opted for Magos solution for no particular reason. Sorry for leaving the thread in flux. |
| deviousdexter is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| WS_POPUP, continuation of old problem | blurrymadness | Windows Programming | 1 | 04-20-2007 06:54 PM |
| Laptop Problem | Boomba | Tech Board | 1 | 03-07-2006 06:24 PM |
| Problem with enum and files | Robert_Sitter | C++ Programming | 1 | 11-24-2005 01:40 AM |
| Sorting problem.. well actually more of a string problem | fatdunky | C Programming | 5 | 11-07-2005 11:34 PM |
| enum code problem | correlcj | C++ Programming | 4 | 11-15-2002 11:00 PM |