Now with
IList<string> listOfStrings = (new string[] { "bob","mary"});
We can not preform
listOfStrings.ToList().ForEach(i => i.DoSome(i)));
We need to reshape to the concrete implementation of the Interface
List<string> listOfStrings = ((new string[] { "bob","mary"}).ToLIst();
Then we can do a for each
listOfStrings.ForEach(i => i.DoSome(i)));
Is this because the foreach operator does not work with the IList Interface and why is this ??
You’re not using the
foreachoperator – you’re using aForEachmethod, which is declared onList<T>(here) and also for arrays. There’s no such extension method onIList<T>orIEnumerable<T>. You could write one, but personally I’d use a realforeachloop:See Eric Lippert’s blog post on the topic for thoughts that are rather more lucid than mine.