fork(1) download
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Globalization;
  5.  
  6. public class Test
  7. {
  8. enum Tst{a,b,c}
  9. public static IDictionary<int, string> GetEnumDictionary<T>() where T : IConvertible
  10. {
  11. return Enum
  12. .GetValues(typeof(T))
  13. .Cast<T>()
  14. .ToDictionary(t => t.ToInt32(CultureInfo.InvariantCulture), t => t.ToString());
  15. }
  16.  
  17. public static void Main()
  18. {
  19. var x = GetEnumDictionary<Tst>();
  20. foreach (var p in x) {
  21. Console.WriteLine("{0} {1}", p.Key, p.Value);
  22. }
  23. }
  24. }
Success #stdin #stdout 0.05s 34016KB
stdin
Standard input is empty
stdout
0 a
1 b
2 c