CodShot
C# Public

Filter a List with LINQ

Filter a list of numbers using a LINQ Where expression.

#csharp #linq #list #filter
C#
using System;
using System.Collections.Generic;
using System.Linq;

List<int> numbers = new() { 3, 8, 12, 15, 20, 21 };

List<int> evenNumbers = numbers
    .Where(number => number % 2 == 0)
    .ToList();

Console.WriteLine(string.Join(", ", evenNumbers));

Notes

LINQ is useful for readable collection queries in C#.

Snippet actions

CodShot user
CodShot user
Updated: 2026-06-08 14:33
Public snippets
0
Forks
CodShot AI Help
Ask about CodShot features, plans, workspace, AI limits, referrals, and public help topics.
Hi! I can help you understand how CodShot works. What would you like to know?
For account-specific or sensitive issues, please open a support ticket. Open support