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