Can you please explain to me what where T : class, new() means in the following line of code?
void Add<T>(T item) where T : class, new();
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That is a constraint on the generic parameter
T. It must be aclass(reference type) and must have a public parameter-less default constructor.That means
Tcan’t be anint,float,double,DateTimeor any otherstruct(value type).It could be a
string, or any other custom reference type, as long as it has a default or parameter-less constructor.