c# - Dropdown to Enum -
i want cast string output of selected value dropdown enum. best way it?
you can wrap extension method make call easier:
public static t toenum<t>(this string value) { if (string.isnullorwhitespace(value)) { throw new argumentnullexception("cannot convert null or empty string enum"); } // enum built-in parse method return (t)enum.parse(typeof(t), value, true); } then call
myvalue.toenum<enumnamehere>(); to enum
Comments
Post a Comment