Want to see what people are talking about? See the latest forum posts.
*/

Other Views

corner
*/

CSHARP FAQ - String Conversion: Numeric Value to an Enumerated Object

How to Convert a string numeric value of an Enum to an enumerated object?

You can use the Parse method of the Enum object.

Say, this is the enum defined:

enum Colors {Red=1, Green=2, Blue=4} 
string mystring="Red";
Colors myEnum=(Colors)Enum.Parse(typeof(Colors),mystring); 
Console.WriteLine("My Color is : {0}", myEnum.ToString());


Index
corner
© 1996-2008 CommunityHeaven LLC. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
North American business development: Nicolai Wadstrom. Publisher: Lars Hagelin.
Resource Listings