Simple question:
If you have a string x
, to initialize it you simple do one of the following:
string x = String.Empty;
or
You need to add a new
constraint for the type parameter T
.
void someMethod(T y) where T : new()
{
T x = new T();
...
}
This will only be valid for types with a default constructor however.
The where
clause for T
is a generic type constraint. In this case, it requires that any type T
this method is applied to must have a public parameterless constructor.