C# and .NET Modern Features

Modern C# features (C# 8-12) and .NET capabilities: nullable reference types, records, pattern matching, LINQ, async streams, minimal APIs.

  • JSON6,465 B
  • YAML4,893 B · −24%
  • TOON4,120 B · −36%

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 it when

  • You need the C# version that introduced a feature and an idiomatic example.
  • You are comparing C# idioms with other languages.

Watch out for

  • 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.

The data

Features

NameVersionDescriptionExampleNotes
Nullable Reference TypesC# 8.0 / .NET Core 3.0Compiler warnings for potential NullReferenceException: string? means nullable, string means non-nullablestring? middleName = null; string firstName = middleName ?? "Unknown";Enable with <Nullable>enable</Nullable> in .csproj
RecordsC# 9.0 / .NET 5Immutable reference types with value equality, positional syntax, with-expressions for non-mutating updatespublic record Person(string FirstName, string LastName); var p2 = p1 with { LastName = "Smith" };Use record class for reference semantics, record struct for value semantics
Pattern MatchingC# 8-12Type patterns, property patterns, relational patterns, list patterns for expressive conditional logicreturn 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)
LINQC# 3.0 / .NET Framework 3.5Language Integrated Query: declarative data querying with deferred execution, query syntax and method syntaxvar adults = people.Where(p => p.Age >= 18).Select(p => p.Name).OrderBy(n => n);Works with any IEnumerable<T>; IQueryable<T> for remote execution (EF Core, SQL)
Async StreamsC# 8.0 / .NET Core 3.0IAsyncEnumerable<T> for asynchronous iteration over sequences, await foreachawait foreach (var item in GetItemsAsync()) { Process(item); }Essential for paginated APIs, database queries, real-time data streams
Minimal APIs.NET 6Simplified 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 ConstructorsC# 12 / .NET 8Constructor parameters directly on class/struct declaration, accessible as instance fieldspublic 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.8Compile-time code generation: analyze syntax trees and emit new C# source files[GenerateSerializer] public class MyData { } // Generates serialization code at compile timeUsed by System.Text.Json, EF Core, gRPC; eliminates runtime reflection overhead

Fields

The shape of this dataset, read from the data itself: every column, its type and a real value. Agents can use this to plan a query without fetching the whole document.

SectionFieldTypeExample
featuresnamestringNullable Reference Types
featuresversionstringC# 8.0 / .NET Core 3.0
featuresdescriptionstringCompiler warnings for potential NullReferenceEx…
featuresexamplestringstring? middleName = null; string firstName = m…
featuresnotesstringEnable with <Nullable>enable</Nullable> in .csp…

Fetch the same bytes

The static files contain the same reference rows as the API, with no API rate limit. Live metadata, such as view counts, may differ. Use the API for content negotiation; use the static files for a cacheable snapshot.

curl "https://yjtoon.com/api/dataset/csharp-dotnet-features?format=toon"
const res = await fetch(
  "https://yjtoon.com/static-data/dataset/csharp-dotnet-features.toon"
);
const toon = await res.text();

Rate limit: 120 requests per minute per IP, no key and no signup. API reference →

Topics

  • csharp
  • dotnet
  • nullable-reference-types
  • records
  • pattern-matching
  • linq
  • async-streams

Search the library

Search by a topic, title, or keyword.

Start with a collection

Browse all 205 datasets