// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; namespace E { public enum OTT { One = 1, Two = 2, Three = 3 } public class Wrapper { private string s; public Wrapper(string s) { this.s = s; } public T ToEnum() { return (T)Enum.Parse(typeof(T), s); } public static implicit operator T(Wrapper o) { return o.ToEnum(); } } public class Program { public static void Main(string[] args) { OTT v1 = (new Wrapper("Two")).ToEnum(); Console.WriteLine(v1); OTT v2 = new Wrapper("Two"); Console.WriteLine(v2); } } }