api: YAML JSON TOON Database version: 1.0.0 format: toon dataset: id: 2361 slug: csharp-dotnet-features title: C# and .NET Modern Features description: "Modern C# features (C# 8-12) and .NET capabilities: nullable reference types, records, pattern matching, LINQ, async streams, minimal APIs." summary: "Modern C# and .NET features with version, description, example and notes: nullable reference types, records, pattern matching, LINQ, async streams, minimal APIs, primary constructors and source generators." use_when[2]: You need the C# version that introduced a feature and an idiomatic example.,You are comparing C# idioms with other languages. caveats[2]: "Features are tied to language versions, which depend on the .NET SDK; check the project's LangVersion.","Some features, such as source generators, need specific tooling support." related[4]: language-comparison-2026,typescript-type-system,behavioral-design-patterns,architectural-design-patterns entry_count: 8 fields[5]{section,field,type,example}: features,name,string,Nullable Reference Types features,version,string,C# 8.0 / .NET Core 3.0 features,description,string,Compiler warnings for potential NullReferenceEx… features,example,string,string? middleName = null; string firstName = m… features,notes,string,Enable with enable in .csp… category: Programming Languages category_slug: programming-languages tags: "csharp,dotnet,nullable-reference-types,records,pattern-matching,linq,async-streams" view_count: 53 created_at: 1778695229 updated_at: 1778695229 data: features[8]{name,version,description,example,notes}: Nullable Reference Types,C# 8.0 / .NET Core 3.0,"Compiler warnings for potential NullReferenceException: string? means nullable, string means non-nullable","string? middleName = null; string firstName = middleName ?? \"Unknown\";",Enable with enable in .csproj Records,C# 9.0 / .NET 5,"Immutable reference types with value equality, positional syntax, with-expressions for non-mutating updates","public record Person(string FirstName, string LastName); var p2 = p1 with { LastName = \"Smith\" };","Use record class for reference semantics, record struct for value semantics" Pattern Matching,C# 8-12,"Type patterns, property patterns, relational patterns, list patterns for expressive conditional logic","return shape switch { Circle c => c.Radius * c.Radius * Math.PI, Rectangle r => r.Width * r.Height, _ => 0 };","Evolves each version: C# 7 (is/switch), C# 8 (property/recursive), C# 10 (extended), C# 12 (list)" LINQ,C# 3.0 / .NET Framework 3.5,"Language Integrated Query: declarative data querying with deferred execution, query syntax and method syntax",var adults = people.Where(p => p.Age >= 18).Select(p => p.Name).OrderBy(n => n);,"Works with any IEnumerable; IQueryable for remote execution (EF Core, SQL)" Async Streams,C# 8.0 / .NET Core 3.0,"IAsyncEnumerable for asynchronous iteration over sequences, await foreach","await foreach (var item in GetItemsAsync()) { Process(item); }","Essential for paginated APIs, database queries, real-time data streams" Minimal APIs,.NET 6,"Simplified HTTP API building without controllers: app.MapGet(\"/\", () => \"Hello\")","var app = WebApplication.Create(args); app.MapGet(\"/todos/{id}\", (int id, TodoDb db) => db.Todos.FindAsync(id));","Reduces boilerplate for small APIs; use for microservices, prototypes, simple backends" Primary Constructors,C# 12 / .NET 8,"Constructor parameters directly on class/struct declaration, accessible as instance fields","public class Person(string firstName, string lastName) { public string FullName => $\"{firstName} {lastName}\"; }",Reduces boilerplate; parameters are in scope for the entire class body Source Generators,.NET 5 / Roslyn 3.8,"Compile-time code generation: analyze syntax trees and emit new C# source files","[GenerateSerializer] public class MyData { } // Generates serialization code at compile time","Used by System.Text.Json, EF Core, gRPC; eliminates runtime reflection overhead"