'buys' operator being defined as: $;
sun $ mysql
oracle $ sun
at the moment, in a parallel universe:
apple $ oracle
bum! that specific universe collapses on itself.
but hey, we're safe.
Wednesday, 22 April 2009
Thursday, 9 April 2009
c# enum and IEquatable
Say you have a generic class like this:
class MyClass<T> where T : IEquatable<T> { }
and an enum:
enum MyEnum { MyOption1, MyOption2, MyOption3 }
would you be able to do this?
MyClass<MyEnum> MyMember;
Nope:
The type 'MyEnum' cannot be used as type parameter 'T' in the generic type or method 'MyClass<T>'. There is no boxing conversion from 'MyEnum' to 'System.IEquatable
What would you do?
Use EqualityComparer<T>.Default. By definition, behaviour is:
The Default property checks whether type T implements the System.IEquatable<T> generic interface and if so returns an EqualityComparer<T> that uses that implementation. Otherwise it returns an EqualityComparer<T> that uses the overrides of Object.Equals and Object.GetHashCode provided by T.
Nice.
class MyClass<T> where T : IEquatable<T> { }
and an enum:
enum MyEnum { MyOption1, MyOption2, MyOption3 }
would you be able to do this?
MyClass<MyEnum> MyMember;
Nope:
The type 'MyEnum' cannot be used as type parameter 'T' in the generic type or method 'MyClass<T>'. There is no boxing conversion from 'MyEnum' to 'System.IEquatable
What would you do?
Use EqualityComparer<T>.Default. By definition, behaviour is:
The Default property checks whether type T implements the System.IEquatable<T> generic interface and if so returns an EqualityComparer<T> that uses that implementation. Otherwise it returns an EqualityComparer<T> that uses the overrides of Object.Equals and Object.GetHashCode provided by T.
Nice.
Subscribe to:
Posts (Atom)