C# Compiled to CIL

c#

Solution

I think you've misunderstood something. The query expression:

var evens = from n in nums where n % 2 == 0 select n;

doesn't compile to:

var evens = nums.Where(n => n % 2 == 0);

Rather, the two lines of code compile directly to CIL. It just so happens that they compile to (effectively) identical CIL. The compiler may convert the query to an intermediate form in the process of analyzing the query code, but the ultimate result is, of course, CIL.

Problem

I understand that the following C# code: ``` var evens = from n in nums where n % 2 == 0 select n; ``` compiles to: ``` var evens = nums.Where(n => n % 2 == 0); ``` But what does it mean that it compiles to that? I was under the impression that C# code compiles directly into CIL?

Original source