I’m struggling with some generics.
The following is my setup:
interface I<T> { }
[...]
void Add<T>(T obj) where T : I<??> { }
How can I ensure that T in the Add method implements I?
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.
The following signature will allow
Addto take anyTthat implementsI<>with any type parameters.The downside of using this method signature is that type inference doesn’t kick in and you have to specify all the type parameters, which looks downright silly:
A much simpler approach is to use the below signature: