convert DataRow col value to enum type

J

John A Grandy

To convert DataRow column values to enum types , I am using :


MyEnum myEnumValue = (MyEnum )Enum.Parse( typeof( MyEnum ),
((int)row["MyEnumId"]).ToString() );



Is there an easier way ?
 
A

Alex Meleta

Hi,

Well, function is an option. Enum.ToObject can also reduce a bit, such as

MyEnum myEnumValue = IntoToMyEnum ((int)row["MyEnumId"]));

function MyEnum IntoToMyEnum( int converted )
{
return (MyEnum)Enum.ToObject(typeof (MyEnum ), converted);
}

Regards, Alex Meleta
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top