Linq implicity typed range variable
<p>With Linq, the range variable (e) can be implicitly typed from the array/collection (emps) it is coming from, but a foreach statement cannot do the same thing without the var keyword, or a type. Why is this?</p>

<p>In ex1 the compiler knows e is of type Employee, without giving a var keyword or anything. Why can't the foreach loop in ex2 do the same thing, you have to provide the type (whether its var or some type).</p>

<p>ex1.</p>

<pre><code>    Employee[] emps = {new Employee ( 1, "Daniel", "Cooley", 7, 57.98M };

    public void SortByLastname()
    {
      var sortedByLastname =
            from e in emps
            orderby e.LastName
            select e.FirstName;
    }
</code></pre>

<p>ex2.</p>

<pre><code>        foreach (Employee empl in emps)
        {
            Console.WriteLine("Employee " + empl);
        }
</code></pre>

<p>This may be over analyzing but i'm trying to get to the bottom of why this is the case.</p>

<p>The answer may very well be Linq query syntax is set up to auto deduce the type of the range variable and the foreach statment is not. Can someone help explain why this is?</p>
