Possible Duplicate:
Enum type constraints in C#
Could somebody kindly explain to me with a simple sample and simple words why enum constraints are not allowed on a generic type i.e. What would happen if they were possible?
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.
Simply put: because they’re not. That’s how the language is designed (you wanted simple, right? 🙂 )
enumis a value type, so you could put a restraint on your generic typewhere T : structand use Type.IsEnum to check in the constructor, throwing an exception if it returns false.