LINQ method syntax in Visual Basic
The same pipeline as lambdas: Where, Select, Count, Average.
Dim readings = {12.5, 48.0, 7.2, 33.1, 60.4, 21.9}
Dim alerts = readings.
Where(Function(r) r > 30).
Select(Function(r) $"high: {r:F1}").
ToList()
For Each alert In alerts
Console.WriteLine(alert)
Next
Console.WriteLine($"cool ones: {readings.Count(Function(r) r < 20)}")
Console.WriteLine($"mean: {readings.Average():F2}")
How it works
Function(r) r > 30is the filter, written inline.- A trailing dot continues the chain on the next line.
Counttakes its own predicate;Averageneeds no lambda at all.
Keywords and builtins used here
DimEachForNextSelect
The run, in numbers
- Lines
- 13
- Characters to type
- 326
- Tokens
- 77
- Three-star pace
- 75 tpm
At the three-star pace of 75 tokens a minute, this run takes about 62 seconds.
Step 2 of 3 in LINQ, step 11 of 29 in Language basics.