CSharp examples for System:Enum
Parses the enum.
using System.Text.RegularExpressions; using System.Text; using System.Security.Cryptography; using System.Numerics; using System.Linq; using System.Globalization; using System.Collections.Generic; using System;//w ww . j ava2 s .c om public class Main{ /// <summary> /// Parses the enum. /// </summary> public static T AsEnum<T>(this string val) where T : struct { T fallBack = default(T); T type; if (String.IsNullOrWhiteSpace(val) || !Enum.TryParse(val, true, out type)) { type = fallBack; } return type; } }