By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,312 Members | 1,850 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,312 IT Pros & Developers. It's quick & easy.

convert DataRow col value to enum type

P: n/a
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 ?
Sep 23 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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

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 ?

Sep 24 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.