0Pricing
C# Academy · Lesson

Select, Where, OrderBy, Take/Skip

Filter with Where, transform with Select, sort with OrderBy/ThenBy, and page with Take/Skip. Simple, readable chains.

Operator roles

Roles:

  • Where filters
  • Select transforms
  • OrderBy/ThenBy sorts
  • Take/Skip page results

Keep chains short and readable.

Filtering with Where

Where keeps items that satisfy a condition (predicate).

using System;
using System.Linq;

public class Program
{
  public static void Main(string[] args)
  {
    int[] nums = new int[] { 1, 2, 3, 4, 5, 6 };

    var evens = nums.Where(n => n % 2 == 0);

    foreach (int n in evens)
    {
      Console.WriteLine(n); // 2 4 6
    }
  }
}

All lessons in this course

  1. IEnumerable pipelines; deferred execution
  2. Select, Where, OrderBy, Take/Skip
  3. Query vs method syntax
← Back to C# Academy