fork download
  1. using System;
  2. using System.Linq;
  3. using System.Linq.Expressions;
  4. using System.Collections.Generic;
  5.  
  6. public class Test
  7. {
  8.  
  9. class Data {
  10. public string Name {get;set;}
  11. public int Number {get;set;}
  12. }
  13. static IEnumerable<Data> Ordered<T>(Func<Data,T> e, IEnumerable<Data> data) {
  14. return data.OrderBy(e);
  15. }
  16. public static void Main()
  17. {
  18. var data = new List<Data>{
  19. new Data {Name = "hello", Number = 2}
  20. , new Data {Name = "world", Number = 1}
  21. };
  22. foreach (var x in Ordered<string>(d => d.Name, data)) {
  23. Console.WriteLine("{0} - {1}", x.Name, x.Number);
  24. }
  25. Console.WriteLine("-------");
  26. foreach (var x in Ordered<int>(d => d.Number, data)) {
  27. Console.WriteLine("{0} - {1}", x.Name, x.Number);
  28. }
  29. }
  30. }
Success #stdin #stdout 0.01s 131776KB
stdin
Standard input is empty
stdout
hello - 2
world - 1
-------
world - 1
hello - 2