Go Back   RunUO - Ultima Online Emulation > Developer's Corner > Programming > C#

C# C# Discussion

Reply
 
Thread Tools Display Modes
Old 03-25-2007, 01:01 AM   #1 (permalink)
Forum Expert
 
Join Date: Dec 2003
Location: Sitting in a chair fulfilling my life's goal
Age: 22
Posts: 2,581
Send a message via AIM to Killamus Send a message via MSN to Killamus
Default Convert string to Enum

Yea, how do I reference a string to an enum, without doing an if statement for each one? For instance
Code:
string WepType = Console.ReadLine();
(WeaponType)WepType = Weapon.Type;
Where Type is of the WeaponType Enum.
__________________
Procrastinators unite!
Tomorrow.
Saying that Java is nice because it works on all OS's is like saying that anal sex is nice because it works on all genders.
Killamus is online now   Reply With Quote
Old 03-25-2007, 01:13 AM   #2 (permalink)
Forum Expert
 
mordero's Avatar
 
Join Date: Nov 2003
Location: Illinois, USA
Age: 21
Posts: 2,911
Default

Code:
string s = Console.ReadLine();
WeaponType type = (WeaponType) Enum.Parse(typeof(WeaponType), s, true);
that should do the trick
mordero is offline   Reply With Quote
Old 03-25-2007, 01:18 AM   #3 (permalink)
Forum Expert
 
Join Date: Dec 2003
Location: Sitting in a chair fulfilling my life's goal
Age: 22
Posts: 2,581
Send a message via AIM to Killamus Send a message via MSN to Killamus
Default

Sweet, thanks.
Quote:
You must spread around more karma before giving it to mordero again.
Damn.
__________________
Procrastinators unite!
Tomorrow.
Saying that Java is nice because it works on all OS's is like saying that anal sex is nice because it works on all genders.
Killamus is online now   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5