I took this from Jon Skeet’s “C# in depth”.
He mentioned the following is valid
(1) class Sample<T> where T:class,Stream
and the following is invalid
(2) class Sample<T> where T:Stream,class
what is the reason for the second one being invalid?
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.
I think that the type constraint by value (
struct) or reference (class) has to be at first place, just like thenewconstraint has to be the last if they are more than one.Also the constraint by itself doesn’t make much sense,
Streamis a class,Twill be a reference type (class) only by that constraint, so basically it’s quite redundant.