fork(8) download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7. Console.WriteLine(ToEnum<int>("2323"));
  8. Console.WriteLine(ToEnum<DateTime>("10/10/10"));
  9. Console.WriteLine(ToEnum<float>("10,656"));
  10. }
  11. public static TEnum ToEnum<TEnum>(String s) where TEnum : struct
  12. {
  13. return (TEnum)(typeof(TEnum)).GetMethod("Parse", new [] { typeof(string) }).Invoke(null, new object[] { s });
  14. }
  15. }
Success #stdin #stdout 0.08s 34248KB
stdin
Standard input is empty
stdout
2323
10/10/2010 12:00:00 AM
10656