Skip to content

Instantly share code, notes, and snippets.

@jfromaniello
Created June 2, 2010 23:36
Show Gist options
  • Save jfromaniello/423183 to your computer and use it in GitHub Desktop.
Save jfromaniello/423183 to your computer and use it in GitHub Desktop.
//this does not compile
new int[] {1, 2, 3, 4, 5, 6}.Select(i => new { i , root = () => i * i }) ;
//this does not compile
var query = from i in new int[] {1, 2, 3, 4, 5, 6}
select new
{
i,
root = () => i * i
};
// this compile:
var query = from i in new int[] {1, 2, 3, 4, 5, 6}
let foo = () => i * i
select new
{
i,
root = foo
};
//however with the last example, this does not compile:
foreach (var item in query)
{
item.root()
}
and the intelliscence seems a little bit crazy:
http://www.screencast.com/users/JoseFR/folders/Jing/media/122504aa-b49f-4ce1-9762-6c893d408e85
//this works fine
var query = new[] {1, 2, 3, 4, 5, 6, 7}.Select(i => {
dynamic expando = new ExpandoObject();
expando.i = i;
expando.root = () => i * i;
return expando
});
foreach(dynamic item in query){
Console.WriteLine(item.root());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment