convert DataRow col value to enum type

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John A Grandy

    convert DataRow col value to enum type

    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 ?


  • Alex Meleta

    #2
    Re: convert DataRow col value to enum type

    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.To Object(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 ?
    >

    Comment

    Working...