Friday, September 15, 2006

Converting a String to an Enumerated Value

Kevin McKneish, a fellow MVP, wrote an interesting tip:

You can convert a string to an enumerated value by using Enum.Parse(). For example, the following code converts the string "Int32" to the corresponding System.Data.DbType enum value:
Param.DbType = (DbType)Enum.Parse(typeof(DbType), "Int32", true);
Useful stuff.

No comments:

Post a Comment