<p>I know that you cannot return anonymous types from methods but I am wondering how the Select extension method returns an anonymous type. Is it just a compiler trick?</p>

<p>Edit</p>

<p>Suppose L is a List. How does this work?</p>

<pre><code>L.Select(s =&gt; new { Name = s })
</code></pre>

<p>The return type is IEnumerable&lt;'a> where 'a = new {String Name}</p>

Well, it's normal type inference for generic method type arguments. For instance:
```
```
List<string> x = new List<string>();

// The compiler converts this:
x.Select(y => y.Length);

// Into this, using type inference:
Enumerable.Select<string, int>(x, y => y.Length);
```
```
The same would be true if
```
x
```
were a list of some anonymous type, or if the inferred return type of the lambda expression were an anonymous type. Don't forget that even though you can't explicitly state the type of a variable which uses an anonymous type, it still does
have
a definite type, known to the compiler.