You haven't actually shown any anonymous types. You've shown a lambda expression. In this case, the compiler will effectively have created an extra method for you, like this:
private static bool SomeUnspeakableName(string X)
{
return X != "1";
}
Then your code will be translated into this, effectively:
List<String> MyList=new List<String>{"0","1","0"}
.Where(new Func<string, bool>(SomeUnspeakableName))
.ToList();
... except actually, the compiler will create a single delegate instance in this case, and cache it. (And of course it will translate the uses of extension methods into normal calls to Enumerable.Where
and Enumerable.ToList
.)
So X
ends up as a string parameter, effectively. At execution time, there's no such thing as a lambda expression (leaving expression trees aside). There's just a delegate created using the generated method.
Now if you were using anonymous types, like this:
var anon = new { Name = "Jon", Age = 34 };
then that would just create a new class, containing a string
variable and an int
variable, and with the same memory footprint as a normal class containing a string
(which is a reference, of course) and an int
.