Monday 15 September 2014

c# - What is the best way to convert List to List? -


I have a list of items called them MyObject and they need to convert them to the list of IMyInterface because I I want to add other things which are not MyObject but also implement my interface. I tried it but it does not work. . list & lt; IMyInterface & gt; MyList = myObjectList; // myObjectList is a list & lt; MyObject & gt;

Any suggestions?

try it

  from the list & lt; IMyInterface & gt; L = myList.OfType & lt; IMyInterface & gt; (). ToList ();    

No comments:

Post a Comment