Converting a String to an Enumerated Value

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);

This is a nice tip that will save you from writing some ugly code!

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>