view plaincopy to clipboardprint?
01.public class Employee
02. {
03. public int ID { get; set; }
04. public string Name { get; set; }
05. public decimal Pay { get; set; }
06. public float Height { get; set; }
07. }
public class Employee
{
public int ID { get; set; }
public string Name { get; set; }
public decimal Pay { get; set; }
public float Height { get; set; }
}
view plaincopy to clipboardprint?
01.class Program
02. {
03. static void Main(string[] args)
04. {
05.
06. IList<Employee> list = new List<Employee>();
07.
08. list.Add(new Employee() { ID = 2, Name = "D", Height = 175.50f, Pay = 6000.45m });
09. list.Add(new Employee() { ID = 4, Name = "A", Height = 178.00f, Pay = 4500.8m });
10. list.Add(new Employee() { ID = 5, Name = "C", Height = 173.54f, Pay = 7500.11m });
11. list.Add(new Employee() { ID = 1, Name = "B", Height = 180.15f, Pay = 8000.2m });
12. list.Add(new Employee() { ID = 3, Name = "E", Height = 182.3f, Pay = 5500.70m });
13.
14. Console.WriteLine("輸出List (ID排序前)");
15.
16. StringBuilder builder = new StringBuilder();
17.
18. foreach (var i in list)
19. {
20. builder.AppendFormat("{0},", i.ID);
21. }
22.
23. Console.WriteLine(builder.ToString().TrimEnd(,));
24. Console.WriteLine("");
25.
26. Console.WriteLine("輸出List (ID排序後)");
27.
28. list = IListOrderBy<Employee>(list, "ID");
29.
30. builder.Length = 0;
31.
32. foreach (var i in list)
33. {
34. builder.AppendFormat("{0},", i.ID);
35. }
36.
37. Console.WriteLine(builder.ToString().TrimEnd(,));
38. Console.WriteLine("");
39.
40.
41. Console.WriteLine("輸出List (Name排序前)");
42.
43. builder.Length = 0;
44.
45. foreach (var i in list)
46. {
47. builder.AppendFormat("{0},", i.Name);
48. }
49.
50. Console.WriteLine(builder.ToString().TrimEnd(,));
51. Console.WriteLine("");
52.
53. Console.WriteLine("輸出List (Name排序後)");
54.
55. list = IListOrderBy<Employee>(list, "Name");
56.
57. builder.Length = 0;
58.
59. foreach (var i in list)
60. {
61. builder.AppendFormat("{0},", i.Name);
62. }
63.
64. Console.WriteLine(builder.ToString().TrimEnd(,));
65. Console.WriteLine("");
66.
67. var tempList = IListOrderBy<Employee>(list, "Height");
68.
69. Console.WriteLine("輸出List (Height排序前) 輸出List (Height排序後)");
70.
71. for (int i = 0, len = list.Count; i < len; i++)
72. {
73. Console.WriteLine(" {0} {1}", list[i].Height, tempList[i].Height);
74. &