C# INTERMEDIATEChapter 4 · C# Intermediate
LINQ Query Expressions
LINQ (Language Integrated Query) allows you to query collections of data directly in C# using syntax similar to SQL, or using method chains.
Worked example
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main() {
int[] scores = { 45, 78, 92, 60 };
var highScores = scores.Where(s => s > 70).OrderBy(s => s);
}
}How it reads
- scores.Where(s => s > 70) filters the array elements
- OrderBy(s => s) sorts the elements in ascending order

Cloud tip: LINQ methods are extension methods on IEnumerable<T> and require the namespace System.Linq.


