Reputation: 27
What is the difference between the two following generic methods where in first method new() is written first and Book is written last and vice-versa for the last method.
public static void Save<T>(T target) where T : new(), Book
{
....
}
and
public static void Save<T>(T target) where T : Book, new()
{
....
}
where Book is a custom class.
Upvotes: 1
Views: 201
Reputation: 101701
The difference is first one does not compile.
From MSDN:
where T : new()
The type argument must have a public parameterless constructor. When used together with other constraints, the new() constraint must be specified last.
Upvotes: 15