.NET developer

Stage 2 · Lesson 4 of 6

Generics, delegates and lambdas

C# for real work: LINQ, collections, generics and async

let you write code once for many types while staying type-safe: List<T>, Task<T>, ILogger<T> and IRepository<T> are all generic. Constraints such as where T : class limit which types fit. Delegates are typed references to methods, and lambdas such as o => o.Total > 1000 are short inline functions.

Func<T, TResult> and Action<T> are the delegate types you will see everywhere: every method takes one, and so does every builder.Services.AddX(options => ...) call in Program.cs. , a static method with a this parameter, are how LINQ and those AddX calls attach to existing types.

You do not need to write clever generic libraries, but you must read generic signatures comfortably.

Common trapa generic repository wrapped around EF Core that hides and loads too much.

A question to check yourself, an AI practice session and 2 cheat sheet entries come with the full roadmap. Unlock

Resources for this stage

Start with· follow one of these

Practise

  • Keep going on the C# track: the later exercises lean on LINQ, generics and dictionaries

  • Solve easy array and hash map problems in C# to make collections and LINQ automatic

Keep handy

  • Return to the official C# modules on collections, LINQ and async when something is unclear

Also worth your time

Mark this stage as not done?