Wednesday, May 9, 2012

How to convert String to Enum Type in C#

This is a common question that we need in most of the time in developing. .NET provides powerful function in Enum Class to do that.

enum DBType
{
SQLSERVER,
ACCESS,
SQLCE
}
private static DBType getDBType()
{
String dbType = "SQLCE";
return (DBType)Enum.Parse(typeof(DBType),dbType);
}
Post a Comment