Generic Constraint

A where clause limiting which types may be used for a generic parameter.

What is Generic Constraint in C#?

Generic Constraint — A where clause limiting which types may be used for a generic parameter.

class Factory
{
    T Create<T>() where T : new()
    {
        return new T();
    }
}

Level: Freelancer · More C# terms at this level

Updated