// 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; namespace Gen { public class Pair where T : IComparable { public T FirstValue { get; set; } public T SecondValue { get; set; } public Pair(T first, T second) { FirstValue = first; SecondValue = second; } public void Swap() { T temp = FirstValue; FirstValue = SecondValue; SecondValue = temp; } public T Max() { if(FirstValue.CompareTo(SecondValue) > 0) { return FirstValue; } else { return SecondValue; } } public override string ToString() { return String.Format("({0},{1})", FirstValue, SecondValue); } } public class Program { public static void Main(string[] args) { Pair ip = new Pair(123, 456); Console.WriteLine(ip); Console.WriteLine(ip.Max()); ip.Swap(); Console.WriteLine(ip); Console.WriteLine(ip.Max()); Pair sp = new Pair("ABC", "DEF"); Console.WriteLine(sp); Console.WriteLine(sp.Max()); sp.Swap(); Console.WriteLine(sp); Console.WriteLine(sp.Max()); Console.ReadKey(); } } }