// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections.Generic; namespace E { public class Data { public int Iv { get; set; } public string Sv { get; set; } public override string ToString() { return "[" + Iv + "," + Sv + "]"; } } public class Program { public static void Main(string[] args) { List lst = new List(); lst.Add(new Data { Iv=2, Sv="CCC" }); lst.Add(new Data { Iv=3, Sv="A" }); lst.Add(new Data { Iv=1, Sv="DDDD" }); lst.Add(new Data { Iv=4, Sv="BB" }); Console.WriteLine("usorteret:"); foreach(Data o in lst) { Console.WriteLine(o); } Console.WriteLine("sorteret efter Iv:"); lst.Sort((Data o1, Data o2) => o1.Iv - o2.Iv); foreach(Data o in lst) { Console.WriteLine(o); } Console.WriteLine("sorteret efter Sv:"); lst.Sort((Data o1, Data o2) => o1.Sv.CompareTo(o2.Sv)); foreach(Data o in lst) { Console.WriteLine(o); } } } }