I believe this is stated in section 7.5.3.2 of the C # 4 specification (Better Function Member).
- Otherwise, if M P has more specific types of parameters than M Q, then M P is better than MQ [...]
- The type parameter is less specific than the nontype parameter.
- [...]
So, a member with a parameter T less specific than a member with an int parameter.
Try to create your own path out of this, just without overloading it. Of course, this is difficult for indeducers, but you can always provide methods (or perhaps just like a recession).
EDIT: note that if you have overloaded methods where both are type parameters, the compiler will complain:
public class Foo<T1, T2> { public void Bar(T1 t1) {} public void Bar(T2 t2) {} } ... Foo<int, int> foo = new Foo<int, int>(); foo.Bar(10);
Here, none of the methods is more specific.
How can I restrict a general parameter from certain types? Since this T can be anything but ints (but for a long time everything is fine)
This is really a completely separate issue, but in principle you cannot. You can restrict type parameters in various ways, but not by explicitly including and excluding types. See the MSDN restrictions page for more information.
source share