from item in range where item % 2 ==0 select i ;
extension methods equivelant of it is.
range.where(item % 2 ==0).select(x=>x).
I feel that first way of linq is translating next one by compiler and if it is,so is there any optimization by compiler like this range.where(item & 2 == 0) instead of other one ?
No the C# compiler will not ever remove the
.Selectcall at the end of the LINQ query. The reason why is that the C# compiler has no knowledge of what the.Selectmethod does and hence cannot remove it as an optimization.The compiler cannot have this knowledge because it binds to
Selectin a very flexible way. It will consider any instance or extension method namedSelecton the target type which has the appropriate signature. You can even define your ownSelectmethods to do customized actions like logging. If the C# compiler removed theSelectclause in this case it would break this type of code.