When specifying a general class new(), it acts as a type constraint T.
In this case, new()declares that the type Tshould be a class with an open constructor without parameters.
For instance:
public class MyGenericClass<T> where T : new()
{
}
public class MyClass
{
public MyClass()
{
}
}
public class MyClass2
{
public MyClass2(int i)
{
}
}
class Program
{
static void Main(string[] args)
{
MyGenericClass<MyClass> c1 = new MyGenericClass<MyClass>();
MyGenericClass<MyClass2> c2 = new MyGenericClass<MyClass2>();
}
}
, T new T(). , T . where T: new() T .
:
if (_Validations == null) {
_Validations = new T();
}
T. T , T new MyType().