1

I want to know whether the Cast() operation is performed on the entire IEnumerable<T> or just on the filtered portion or it.

Andre Pena
  • 56,650
  • 48
  • 196
  • 243
  • 2
    You might want to have a look at my question which is related and answers your question indirectly: [Order of LINQ extension methods does not affect performance?](http://stackoverflow.com/questions/10110013/order-of-linq-extension-methods-does-not-affect-performance) – Tim Schmelter Nov 16 '12 at 12:58

1 Answers1

3

Linq operations are deferred, only the first element will be cast and then returned.

You can try it yourself:

object[] objects = new object[] { 123, "string" };
objects.Cast<int>().First();
strmstn
  • 852
  • 6
  • 10