public static void Go() { #if EIMITypeSafety_Version1 SomeValueType v = new SomeValueType(0); Object o = new Object(); Int32 n = v.CompareTo(v); // Undesired boxing n = v.CompareTo(o); // InvalidCastException #endif #if EIMITypeSafety_Version2 SomeValueType v = new SomeValueType(0); Object o = new Object(); Int32 n = v.CompareTo(v); // No boxing n = v.CompareTo(o); // compile-time error #endif #if EIMITypeSafety_Version3 SomeValueType v = new SomeValueType(0); IComparable c = v; // Boxing! Object o = new Object(); Int32 n = c.CompareTo(v); // Undesired boxing n = c.CompareTo(o); // InvalidCastException #endif }
public Int32 CompareTo(SomeValueType other) { return(m_x - other.m_x); }