Can I cast
IInterface<MyClass>
to
IInterface<IAnother>
when MyClass implements IAnother?
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.
Yes, but only if your’re using C# 4 (or beyond) and,
IInterfaceis declared asIInterface<out T>.This is called generic covariance, you can find more information on MSDN, or this (more formal but more understandable) introduction from Bart de Smet.