public int CompareTo(object o) { if (o is Foo) { return IntValue.CompareTo(((Foo)o).IntValue); } else if (o is Bar) { return IntValue.CompareTo(((Bar)o).IntValue); } throw new ArgumentException("Object is not a Foo or a Bar"); } }