Skip to content
dreamcode
dreamcode
Map
LINQ queries
Lesson 13 of 21
+15 XP on finish
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.

Check your understanding

0 / 2

Answer all 2 to complete this lesson and earn 15 XP.

  1. 1. Which namespace provides the LINQ extension methods such as Where and Select?
  2. 2. What is a lambda expression in LINQ, like s => s > 70?
Answer every question to unlock the next lesson.