C# Tutorials: Language Features, Patterns and Performance

Last updated: October 22, 2026

Every C# language article on this site in one place: what changed in recent versions, the core features you use daily, writing fast code, design patterns, testing, and writing secure code. Posts marked tested on .NET 10 were rewritten from a working project, with real compiler errors, output and measurements.

Hit one of these? Start here

You see thisRead this
CS0403 Cannot convert null to type parameter ‘T’, CS0019 Operator ‘==’ cannot be applied to operands of type ‘T’, CS0310, CS0311C# generic compiler errors and fixes
Soft-deleted rows come back, or Remove hard-deletes, after switching to a generic repositoryRepository pattern pitfalls with EF Core
Extension methods (here: LoggerExtensions.LogInformation) may not be used in setup / verification expressions, Non-overridable members may not be used, or CS8602 after upgrading to Moq 4.21Moq errors and fixes
Sequence contains no elements, Sequence contains more than one matching element, or EF Core could not be translatedLINQ examples on .NET 10
CS0144 cannot create an instance of the abstract type or interface, CS0535 does not implement interface member, or CS1721 multiple base classesInterface vs abstract class
CS9057 analyzer references a newer version of the compiler, or a source generator that silently does not runSource generators on .NET 10
CS0131 on new int[5] { [^1] = 1 }, or not sure which C# 13/14 feature needs which .NET versionC# 13 and C# 14 features
CS0518 Predefined type ‘IUnion’ is not defined, CS1001/CS8803 on a union line, or JSON “ambiguous for union type”C# 15 union types errors
arr.Reverse() reverses the array in place after upgrading to C# 14, or MemoryExtensions.Contains in an expression treeC# 14 breaking changes, reproduced
params ReadOnlySpan<T> and an existing array picking different overloadsC# 13: params collections, measured
CS0150 when the column width in {value,width} is a variableString interpolation and alignment
The JSON value could not be converted to System.Int32 or A possible object cycle was detected after moving off NewtonsoftSystem.Text.Json vs Newtonsoft migration gotchas
Two SaveChanges calls and half the data written after a failureRepository and Unit of Work with EF Core
CS8618, CS8602, CS8600 or CS8604 after turning on <Nullable>enable</Nullable>Nullable reference types
Visual Studio suggests IDE0290 Use primary constructor and you are not sure it is safePrimary constructors explained

1. What’s new in C#

  • C# 15 union types: the new union keyword, exhaustive switch and CS8509, why a union boxes value types, the default trap, System.Text.Json type classifiers and closed hierarchies. (tested on .NET 11 RC2)
  • C# 14 and C# 13 features: C# 14 extension members, the field keyword, null-conditional assignment and the breaking changes from first-class spans, plus C# 13 params collections with measured allocations and the Lock type benchmarked. (tested on .NET 10)
  • Primary constructors: what IDE0290 really changes and how to turn it off, the hidden fields the compiler generates, the CS9124 double-storage bug, DI and JSON gotchas. (rewritten and tested on .NET 10)
  • Pattern matching: type, property and list patterns, switch expressions and when guards.
  • Nullable reference types: every CS86xx warning with the code that causes it, enable vs warnings vs annotations, the attributes, and where nulls still get in (JSON, ASP.NET Core validation, EF Core migrations). (rewritten and tested on .NET 10)
  • Records vs classes vs structs: value vs reference semantics and a decision cheat sheet.
  • Extension methods: writing them well, real examples, and extension members in C# 14.

2. Core language

  • Generics: constraints, generic math, the == trap on a generic T, measured boxing costs and fixes for the common generic compiler errors. (tested on .NET 10)
  • Delegates, events, Func and Action: from a delegate type to events with EventHandler<T>, and the closure trap in loops.
  • Interface vs abstract class: a comparison table, the compiler errors (CS0144, CS0535, CS0534, CS1721), why a default interface method is not on the class (CS1061), static abstract members and struct boxing. (rewritten and tested on .NET 10)
  • Async/await: how it works underneath, concurrent calls, and the common mistakes.
  • System.Text.Json vs Newtonsoft.Json: the defaults that silently break a migration, the exact exception messages, polymorphism, source generation and a benchmark. (tested on .NET 10)
  • Exception handling: custom exceptions, logging them properly, and exceptions vs the Result pattern.
  • LINQ examples: the everyday operators with real output, CountBy/AggregateBy (.NET 9), LeftJoin/RightJoin (.NET 10), the exceptions LINQ throws, deferred execution and EF Core translation. (rewritten and tested on .NET 10)
  • Access modifiers: public, private, protected, internal and protected internal in one short reference.

3. Strings, collections and performance

Measure before you optimise; the profiling guide shows how.

4. Design and architecture

  • SOLID principles: each principle with a C# example, plus interview-style quick answers.
  • Design patterns: factory, singleton, observer and strategy, and how to choose.
  • Dependency injection: constructor injection, scoped vs transient vs singleton, and keyed services.
  • Repository pattern: specific vs generic repositories on EF Core 10, the soft-delete bugs a generic base introduces, global query filters, and why mock tests miss them. (tested on .NET 10)
  • Repository and Unit of Work with EF Core: seven runs against a real database showing what one SaveChanges does and does not protect. (rewritten and tested on .NET 10)
  • Domain-driven design: entities, value objects, aggregates and domain events.
  • Event-driven architecture: from C# events to MediatR domain events to integration events between services.

5. Testing and team practice

  • Moq tutorial: Setup, ReturnsAsync, Verify, Callback, strict mocks, verifying ILogger and mocking HttpClient, with the exact text of 10 Moq errors and the CS8602 warning Moq 4.21 adds. (tested on .NET 10)
  • TDD with xUnit and Moq: red-green-refactor on an order service and isolating dependencies with Moq.
  • CSharpier vs dotnet format: the same messy file through both formatters, the .editorconfig conflict that fails CI, and timings on 3,050 files. (tested on .NET 10)
  • Code review checklist: what to look for in a C# pull request and a one-page checklist.
  • Git for .NET teams: trunk-based branching, commits and pull requests that stay reviewable.

6. Writing secure C#

7. C# beyond the backend

  • .NET MAUI: a first cross-platform app with XAML, MVVM and API calls.
  • C# for Unity: how Unity C# differs, events and time, the fake-null trap and performance.

Related guides

Building web APIs with these features? The ASP.NET Core tutorials guide covers APIs, security, observability and deployment.