Let's suppose I have a method like this:
public IEnumerable<string> GetList()
{
var list = new List<string>()
{
"1",
"2"
};
return list;
}
The method returns an IEnumerable<string>
, in the method though I return a List, because the List derives from IEnumerable (wrong word I guess, correct me if I'm wrong) this is possible.
But when I use the returned value in another place such as:
var returnList = GetList();
Now, returnList is a IEnumerable and that's totally fine.
My questions are:
- Is the value converted into IEnumerable when I return it as a List in the method?
- If there is, does this conversion slow down the general program, just like
ToList()
does?