Well, you define a generic function, so you need to determine the exact type that it has to deal with. Because if you give only numbers ( 1 , 2 , 3 , 4 , etc.) for the function. They may just be something : short , ushort , integer ...
So you can do:
or
ushort p = 3; if (p.In<ushort>(1, 2, 3, 4, 5)) return;
Or, as you did in your second example, add each parameter to the type you want:
ushort p = 3; if (p.In((ushort)1, (ushort)2, (ushort)3, (ushort)4, (ushort)5)) return;
I personally would prefer the first case.
EDIT
How about why it works in this case:
ushort p = 3; if (Extensions.In(p, 1, 2, 3, 4, 5)) return;
is that you explicitly pass as this (first parameter) p , which is a known type for the compiler, so it can output it.
The default type is for 1, 2, 3, 4, etc. - int . Therefore when you call
p.In(1, 2, 3, 4, 5)
T treated (or tends to be) as an integer . Since the compiler has no guarantee that there would be no lost data (when you use ushort on integer), it gives an error message. This forces you to explicitly define a smaller type.
Note: function parameters are defined as T[] , so you pass integers (at least the compiler thinks about it), but pretending to be ushort (since you are calling the ext method from p ).
For proof, try running
int p = 3; if (p.In(1, 2, 3, 4, 5)) return;
This works great.