C# – What Does new() Mean in Generics?

c++genericsnew-operator

There is an AuthenticationBase class in WCF RIA Services. The class definition is as follows:

// assume using System.ServiceModel.DomainServices.Server.ApplicationServices

public abstract class AuthenticationBase<T> 
    : DomainService, IAuthentication<T> 
    where T : IUser, new()

What does new() mean in this code?

Best Answer

It's the new constraint.

It specifies that T must not be abstract and must expose a public parameterless constructor in order to be used as a generic type argument for the AuthenticationBase<T> class.

Related Question