// 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; namespace DotnetVersusJava { public class Data : IComparable { private int iv; private string sv; public Data() : this(0, "") { } public Data(int iv, string sv) { this.iv = iv; this.sv = sv; } public int Iv { get { return iv; } set { iv = value; } } public string Sv { get { return sv; } set { sv = value; } } public override string ToString() { return (iv + ":" + sv); } public int CompareTo(object o) { return (iv - ((Data)o).iv); } } public class Test { public static void Main(string[] args) { ArrayList lst = new ArrayList(); lst.Add(new Data(2, "BB")); lst.Add(new Data(3, "CCC")); lst.Add(new Data(1, "A")); lst.Sort(); for(int i = 0; i < lst.Count; i++) { Data d = (Data)lst[i]; Console.WriteLine(d); } } } }