Filter and Project Products
A query can filter, order, and project without modifying its source collection.
How it works
Create a LINQ pipeline over product records.
Anonymous objects are useful for short-lived projections that do not need a named type.
Runnable C# example
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));
}
}
Book, BagPractice 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.