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

Andre Pena
- 56,650
- 48
- 196
- 243
-
2You 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 Answers
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
-
1This is a good way of checking it out which I didn't think of. Thank you @strmstn – Andre Pena Nov 16 '12 at 12:57