C# Practice Exercises

Filter and Project Products

Create a LINQ pipeline over product records.

Introduction

A query can filter, order, and project without modifying its source collection.

Anonymous objects are useful for short-lived projections that do not need a named type.

Runnable C# example

C#
Run code →
Program.cs
using System;
using System.Linq;
record Product(string Name, decimal Price);
class Program
{
    static void Main()
    {
        var products = new[] { new Product("Book", 30), new Product("Pen", 5), new Product("Bag", 45) };
        var names = products.Where(p => p.Price >= 20).OrderBy(p => p.Price).Select(p => p.Name);
        Console.WriteLine(string.Join(", ", names));
    }
}
Result of running the code
Book, Bag

Practice with the debugger

Set a breakpoint on an important assignment or condition, click Debug, and inspect the local values before stepping to the next line.

Practice with a challenge

Use what this lesson covers to solve a real problem. Each challenge runs in your browser with instant tests and an AI review.

All challenges