This question is about when you do this, and you don't need to include type argument spec arguments. It is a little long, so please feel free to.
If you have the following (far-fetched) classes ...
public abstract class UserBase { public void DoSomethingWithUser() { } } public class FirstTimeUser : UserBase { }
Next method ...
private static void DoThingsWithUser<TUser>(TUser user) where TUser : UserBase { user.DoSomethingWithUser(); }
It can be called with or without an argument of type TUser ...
var user = new FirstTimeUser(); DoThingsWithUser<FirstTimeUser>(user); DoThingsWithUser(user);
So far so good.
But if you add a couple more (again, far-fetched) classes ...
public abstract class UserDisplayBase<T> where T : UserBase { public T User { get; protected set; } } public class FirstTimeUserDisplay : UserDisplayBase<FirstTimeUser> { public FirstTimeUserDisplay() { User = new FirstTimeUser(); } }
And the method ...
private static void DoThingsWithUserDisplay<TDisplay, TUser>(TDisplay userDisplay) where TDisplay : UserDisplayBase<TUser> where TUser : UserBase { userDisplay.User.DoSomethingWithUser(); }
When calling this method, you must include arguments of the type ...
var userDisplay = new FirstTimeUserDisplay(); DoThingsWithUserDisplay<FirstTimeUserDisplay, FirstTimeUser>(userDisplay);
If you do not specify type arguments, you will get a compiler error
Type arguments for the DoThingsWithUserDisplay (TDisplay) method cannot be taken out of use. Try explicitly specifying type arguments.
I think the compiler should / could be smart enough to figure this out ... or is there a subtle reason why not?