namespace SortableLists
{
using System;
using System.Collections.Generic;
public class Program
{
private static void Main() {
var list = new List<ListItem>
{
new ListItem {AdmissionCode = "801r", Name = "Rajesh Koothrappali", RollNumber = 54},
new ListItem {AdmissionCode = "892k", Name = "Leonard Leakey Hofstadter", RollNumber = 34},
new ListItem {AdmissionCode = "1203a", Name = "Sheldon Lee Cooper", RollNumber = 46},
new ListItem {AdmissionCode = "802x", Name = "Howard Wolowitz", RollNumber = 98}
};
list.ForEach(x => Console.WriteLine(x.RollNumber + ","+x.Name + "," + x.AdmissionCode));
Console.Write("\n");
list.Sort();
list.ForEach(x => Console.WriteLine(x.RollNumber + "," + x.Name + "," + x.AdmissionCode));
Console.ReadKey();
}
}
public class ListItem : IComparable<ListItem>
{
public int RollNumber { get; set; }
public string Name { get; set; }
public string AdmissionCode { get; set; }
#region Implementation of IComparable<in ListItem>
public int CompareTo(ListItem other) {
return AdmissionCode.CompareTo(other.AdmissionCode);
}
#endregion
}
}
我不知道这是什么排序,录取代码1203 Sheldon博士排序后出现在列表顶部???我期待 801,802,803 和 1203 ......谁能解释一下?