Converts the string representation of the name or numeric value of one or more enumerated constants to an equivalent enumerated object.
public static class Helper {
public static T ParseToEnum(this string enumText) { try { return (T)Enum.Parse(typeof(T), enumText, true); } catch { return default(T); } }
//Sample enum enum Sample {
yes, no, alright }
//Method Usage protected void Page_Load(object sender, EventArgs e) { Helper.ParseToEnum("2");
}
//Output:
//alright
//the second value
|
No responses found. Be the first to respond and make money from revenue sharing program.
|