1)When I have
Static void Sample<T>(T a,T b)
Does the declaration Sample enforce that all parameters need to be of type T ?
2) Does the declaration Static void Sample(T a,T b)
not a Generic method unless i specify
Sample<T>
?
1)When I have
Static void Sample<T>(T a,T b)
Does the declaration Sample enforce that all parameters need to be of type T ?
2) Does the declaration Static void Sample(T a,T b)
not a Generic method unless i specify
Sample<T>
?
indeed, in your example, both parameters are of type T therefore need to ..um.. be of type T. You could of course declare a method that uses different types.
static void Sample<T>(T a,SomeType b)
Yes, it is not generic unless you specify Sample<T>(T a,T b)
1) Yes
2) Yes, this is invalid syntax for a generic method
EDIT: More almost instantaneous answering :)
Yes, the declaration enforces that all of the declared parameters need to be of type T.
static void Sample(T a, T b)
will fail to compile (unless you have a type T) because it is not a generic declaration. You need the for the declaration to be a generic.
1) No, Static void Sample<T>(T a,T b)
does not enforce all parameters to be of type T. You can have other parameters in method arguments also. EDIT:- You can have Sample(T a, int b, string s) (if this is what you mean)
2) Yes, Static void Sample(T a,T b)
is non-generic and compiler will throw exception about type T (if you don't have a classed named T)