I know I can cast an object from its own type to its interface type like so:
IMyInterface myValue = (IMyInterface)MyObjectThatImplementsMyInterface;
How can I cast IList<MyClassThatImplementMyInterface> to IList<IMyInterface>?
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 answered the same question yesterday, although for base classes rather than interfaces.
The way to make this work is to iterate over the list and cast the elements. This can be done using ConvertAll:
You could also use Linq: