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
}
}
Ich weiß nicht, was das für eine Sortierung ist, bei der der Zulassungscode 1203 Dr. Sheldon nach der Sortierung ganz oben in der Liste auftaucht... ich hatte 801, 802, 803 und 1203 erwartet... kann das jemand erklären?