Query syntax in C#
The same LINQ, shaped like the SQL it borrowed from.
var scores = new[] { 91, 62, 85, 45, 78, 96 };
// query syntax: the same LINQ, shaped like SQL
var passing =
from s in scores
where s >= 60
orderby s descending
select s;
Console.WriteLine(string.Join(",", passing));
Console.WriteLine(passing.First());
How it works
from ... where ... selectreads top to bottom.orderby s descendingsorts inside the query.- The result is a normal lazy sequence;
First()still works.
Keywords and builtins used here
descendingfrominneworderbyselectstringvarwhere
The run, in numbers
- Lines
- 11
- Characters to type
- 254
- Tokens
- 63
- Three-star pace
- 95 tpm
At the three-star pace of 95 tokens a minute, this run takes about 40 seconds.
Step 1 of 3 in Query syntax, step 10 of 17 in LINQ in depth.