It’s part curiosity and part because I was just trying to use this. If you have the following definitions, this is not allowed by the compiler because it says that the member is already defined. What’s the reasoning behind not allowing exclusive overloads of generic type parameters?
void Get<T>() where T: struct {}
void Get<T>() where T: class {}
It seems to me that there’s no inherent problem with this. One might argue that it is not always clear which the compiler should choose in cases where the definitions overlap (but a common resolution seems to be most specific match first).
Can someone help me understand or point to a resource what the reasoning is behind disallowing this?
Eric Lippert already answered this one, in a blog post on generic constraints and method signatures: http://blogs.msdn.com/b/ericlippert/archive/2009/12/10/constraints-are-not-part-of-the-signature.aspx
Constraints on generic types are not part of method signatures in the CLR, therefore you can’t have two methods that differ only in generic type constraints. Without CLR support it would be quite fiddly to get C# to support these in a sensible fashion that is compatible with other .NET languages.