Friday, 15 June 2012

.net - Casting a list of objects to their interface type in C# -


I know that I can remove an object from my own type of type in my own way like this:

  IMyInterface myValue = (IMyInterface) MyObjectThatImplementsMyInterface;  

I IList to IList & lt; IMyInterface & gt;

How do I put

I answered the same question though For base classes instead of interface.

How to make this work the list and elements inserted can be done using the Converted Around:

  IList & lt; A & gt; ListOfA = new list & lt; C & gt; (). ConvertAll (x = & gt; (A) x);  

You can also use the link:

  IList & lt; A & gt; ListOfA = new list & lt; C & gt; (). Cast & lt; A & gt; (). ToList ();  

No comments:

Post a Comment