Skip to content

Instantly share code, notes, and snippets.

@dlhartveld
Created February 16, 2013 01:41
Show Gist options
  • Save dlhartveld/4965058 to your computer and use it in GitHub Desktop.
Save dlhartveld/4965058 to your computer and use it in GitHub Desktop.
A simple example of a LINQ query over a collection of objects (strings, in this case). helloLength1 and helloLenght2 are equivalent - the compiler just desugars the LINQ expression to the same AST that the second expression results in.
List<string> ss = new List<string>();
ss.Add("Hello");
ss.Add("World");
var helloLength1 = from s in ss
where s.StartsWith("H")
select s.Length;
var helloLength2 = ss.Where(s => s.StartsWith("H")).Select(s => s.Length);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment