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

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -