-
Notifications
You must be signed in to change notification settings - Fork 2
CSharp LINQ Async Overview
Joe Care edited this page Dec 22, 2025
·
1 revision
This lesson briefly shows how LINQ and async/await can be combined in typical scenarios.
Related wiki pages:
- LINQ basics:
CSharp-LINQ-Where-OrderBy.md,Lesson10.12.2025.md - Async basics:
CSharp-AsyncAwait-Basics.md,Lesson09.12.2025.md
using System;
using System.Collections.Generic;
using System.Linq;
var numbers = new List<int> { 1, 2, 3, 4, 5 };
var evenSquares = numbers
.Where(n => n % 2 == 0)
.Select(n => n * n);
Console.WriteLine(string.Join(", ", evenSquares)); // 4, 16using System.Collections.Generic;
using System.Threading.Tasks;
async Task<List<int>> GetNumbersAsync()
{
await Task.Delay(500); // simulate async work
return new List<int> { 1, 2, 3, 4, 5 };
}using System;
using System.Linq;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
var numbers = await GetNumbersAsync();
var greaterThanTwo = numbers.Where(n => n > 2).ToList();
Console.WriteLine(string.Join(", ", greaterThanTwo)); // 3, 4, 5
}
static async Task<System.Collections.Generic.List<int>> GetNumbersAsync()
{
await Task.Delay(500);
return new() { 1, 2, 3, 4, 5 };
}
}- Deepen your LINQ knowledge with the dedicated LINQ lessons.
- Deepen async understanding with HTTP and file examples in
Lesson09.12.2025.mdandLesson16.12.2025.md.