I'm still learning some of this c# stuff, and I couldn't find an answer to this question. Assuming that I have a list of MyObject implementing MyInterface
public class MyObject : IMyInterface { ...}
public List<MyObject> MyObjectList;
How can I return an IEnumerable<IMyInterface>
with the contents of MyObjectList?
I mean, right now I have this:
List<IMyInterface> temp = new List<IMyInterface>();
foreach (MyObject obj in MyObjects) temp.Add(obj);
return (IEnumerable<IMyInterface>)temp;
But is it necessary to create a new list like this?
Thank you.