// 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; public class Foobar : IComparable { private int a; private string b; public Foobar() : this(0, "") { } public Foobar(int a, string b) { this.a = a; this.b = b; } public int A { get { return a; } set { a = value; } } public string B { get { return b; } set { b = value; } } public int CompareTo(object o) { if(b == "SPECIAL") { return 1; } if(((Foobar)o).B == "SPECIAL") { return -1; } return (a - ((Foobar)o).A); } public override string ToString() { return ("(" + a + "," + b + ")"); } } class SpecialSort { public static void Main(string[] args) { Foobar[] arr = new Foobar[6]; arr[0] = new Foobar(3, ""); arr[1] = new Foobar(2, "SPECIAL"); arr[2] = new Foobar(6, ""); arr[3] = new Foobar(1, ""); arr[4] = new Foobar(5, "SPECIAL"); arr[5] = new Foobar(4, ""); Array.Sort(arr); for(int i = 0; i < arr.Length; i++) { Console.WriteLine(arr[i]); } } }