5. Advanced Features Timeline


Part 1: C# Version Timeline

C# Evolution Overview

2002 ────> 2007 ────> 2012 ────> 2017 ────> 2020 ────> 2024
  │          │          │          │          │          │
C# 1.0     C# 3.0    C# 5.0    C# 7.0    C# 9.0    C# 13.0
  │          │          │          │          │          │
Classes    LINQ      async/    Pattern   Records   params
Delegates           await     Matching            collections

Major Themes by Version

Era
Versions
Major Theme

Foundation

C# 1.0-2.0 (2002-2005)

Object-oriented basics, Generics

LINQ Era

C# 3.0-4.0 (2007-2010)

Query syntax, Functional programming

Async Era

C# 5.0-6.0 (2012-2015)

Asynchronous programming

Modern Era

C# 7.0-8.0 (2017-2019)

Pattern matching, Nullable types

Unified .NET

C# 9.0-13.0 (2020-2024)

Records, Simplification, Performance


Version-by-Version Features

C# 1.0 (.NET Framework 1.0, 2002) 🏛️ Foundation

The Beginning

Key Features:

  • Classes, structs, interfaces, enums

  • Properties, events, delegates

  • Value types vs reference types

  • Operators and expressions

  • Attributes


C# 2.0 (.NET Framework 2.0, 2005) 🔥 Generics!

Game Changer: Type Safety

Key Features:

  • Generics (List<T>, Dictionary<TKey,TValue>)

  • Nullable value types (int?, Nullable<T>)

  • Anonymous methods

  • Iterators (yield return, yield break)

  • Partial types (partial class)

  • Static classes

  • Null-coalescing operator (??)

  • Covariance and contravariance (delegates)


C# 3.0 (.NET Framework 3.5, 2007) 🚀 LINQ Revolution

Game Changer: Query Syntax

Key Features:

  • LINQ (Language Integrated Query)

  • Lambda expressions (x => x * 2)

  • Extension methods (this parameter)

  • Anonymous types

  • Auto-implemented properties

  • Object and collection initializers

  • Expression trees (Expression<T>)

  • Partial methods

  • Implicit typing (var)


C# 4.0 (.NET Framework 4.0, 2010) 🔀 Dynamic

Key Features:

  • dynamic type (late binding)

  • Named arguments

  • Optional parameters

  • Generic covariance and contravariance

  • Embedded interop types (COM)


C# 5.0 (.NET Framework 4.5, 2012) ⏳ Async Revolution

Game Changer: Asynchronous Programming

Key Features:

  • async/await (asynchronous programming)

  • Caller information attributes (CallerMemberName, CallerFilePath, CallerLineNumber)


C# 6.0 (.NET Framework 4.6, 2015) ✨ Syntax Sugar

Key Features:

  • String interpolation ($"{name}")

  • Null-conditional operators (?., ?[])

  • Expression-bodied members

  • Auto-property initializers

  • nameof operator

  • Index initializers

  • Exception filters (when)

  • using static


C# 7.0 (.NET Framework 4.7, 2017) 🎯 Pattern Matching

Game Changer: Pattern Matching & Tuples

Key Features:

  • out variables (inline declaration)

  • Tuples ((int, string) syntax)

  • Pattern matching (is, switch)

  • Deconstruction

  • Local functions

  • Ref returns and ref locals

  • Generalized async return types (ValueTask<T>)

  • Expression-bodied constructors/finalizers

  • Throw expressions

  • Binary literals (0b) and digit separators (_)


C# 7.1-7.3 (2017-2018) 🔧 Refinements

Key Features:

  • Async Main

  • Default literal expressions

  • Inferred tuple names

  • readonly struct (C# 7.2)

  • ref struct (C# 7.2)

  • in parameters (C# 7.2)

  • private protected modifier (C# 7.2)

  • Tuple equality (C# 7.3)


C# 8.0 (.NET Core 3.0, 2019) ✅ Nullable References

Game Changer: Nullable Reference Types

Key Features:

  • Nullable reference types (string?, #nullable enable)

  • Switch expressions (concise syntax)

  • Property patterns in pattern matching

  • Tuple patterns

  • Positional patterns

  • Indices and ranges (^, ..)

  • using declarations (simplified)

  • Static local functions

  • Null-coalescing assignment (??=)

  • Async streams (IAsyncEnumerable<T>, await foreach)

  • Default interface methods


C# 9.0 (.NET 5.0, 2020) 📝 Records

Game Changer: Records & Init

Key Features:

  • Records (immutable data classes)

  • Init-only setters (init accessor)

  • Top-level statements (no Main method)

  • with expressions (non-destructive mutation)

  • Target-typed new

  • Relational patterns (>=, <, etc.)

  • Logical patterns (and, or, not)

  • Covariant return types

  • Function pointers

  • Native integers (nint, nuint)

  • Module initializers


C# 10.0 (.NET 6.0, 2021) 🌍 Global Usings

Key Features:

  • Global using directives (project-wide usings)

  • File-scoped namespaces (less indentation)

  • Record structs

  • with expressions on structs

  • Lambda improvements (natural types, attributes)

  • CallerArgumentExpression

  • Constant interpolated strings

  • Extended property patterns

  • Enhanced #line pragma

  • Implicit usings (.NET 6 SDK feature)


C# 11.0 (.NET 7.0, 2022) 🔤 Raw Strings

Key Features:

  • Raw string literals ("""...""")

  • List patterns ([1, 2, ..])

  • required members (force initialization)

  • Generic math support (INumber<T>)

  • Static abstract members in interfaces

  • UTF-8 string literals ("text"u8)

  • Pattern match Span<char>

  • Newlines in interpolations

  • File-local types (file modifier)

  • Auto-default structs

  • nameof with parameters


C# 12.0 (.NET 8.0, 2023) 🏗️ Primary Constructors

Key Features:

  • Primary constructors (for classes and structs)

  • Collection expressions ([1, 2, 3])

  • Spread operator (.. in collections)

  • Lambda optional parameters

  • ref readonly parameters

  • Alias any type

  • Inline arrays

  • Experimental attributes

  • Interceptors


C# 13.0 (.NET 9.0, 2024) 📦 Latest

Key Features:

  • params collections (not just arrays)

  • New Lock type (System.Threading.Lock)

  • \e escape sequence (ANSI codes)

  • Implicit indexer access in object initializers

  • Partial properties and indexers

  • ref and unsafe in iterators and async

  • Overload resolution priority attribute


Part 2: Advanced Features Deep Dive

Tuples and Deconstruction

System.Tuple (C# 4.0) - Legacy ❌

ValueTuple (C# 7.0+) - Modern ✅

When to Use Tuples:

  • ✅ Returning multiple values from methods

  • ✅ Grouping related data temporarily

  • ✅ LINQ projections

  • ❌ Don't use for complex types (use classes/records)

  • ❌ Don't use for public APIs (use proper types)

Performance:

  • ValueTuple is a struct (stack-allocated)

  • Much faster than System.Tuple (class/heap)

  • Zero allocation for local tuples


Pattern Matching Complete Guide

Type Patterns (C# 7.0)

Constant Patterns (C# 7.0)

Property Patterns (C# 8.0)

Tuple Patterns (C# 8.0)

Positional Patterns (C# 8.0)

Relational Patterns (C# 9.0)

Logical Patterns (C# 9.0)

List Patterns (C# 11.0)


Nullable Reference Types (C# 8.0+)

Migration Strategy:

  1. Enable nullable in new projects

  2. For existing projects, enable file-by-file

  3. Fix warnings gradually

  4. Use ! operator sparingly


Indices and Ranges (C# 8.0+)


Span<T> and Memory<T> (C# 7.2+)

Purpose: Zero-allocation slicing of arrays, strings, or stack memory.

Key Differences:

  • Span<T>: Stack-only, cannot be field, fastest

  • Memory<T>: Can be stored in fields, slightly slower

  • ReadOnlySpan<T>: Immutable span


ref struct and ref Safety (C# 7.2+)


Iterators and yield (C# 2.0+)

Behind the Scenes:

  • Compiler generates state machine

  • Maintains state between calls

  • Efficient memory usage


Async Streams (C# 8.0+)

Use Cases:

  • Streaming API responses

  • Database cursors

  • Real-time data feeds

  • Paginated results


Modern C# Simplifications

Top-level Statements (C# 9.0+)

Global Usings (C# 10.0+)

File-scoped Namespaces (C# 10.0+)

Raw String Literals (C# 11.0+)

Collection Expressions (C# 12.0+)


Part 3: Quick Reference Cards

Version Feature Matrix

Feature
Version
.NET Version

Generics

C# 2.0

.NET Framework 2.0

LINQ

C# 3.0

.NET Framework 3.5

dynamic

C# 4.0

.NET Framework 4.0

async/await

C# 5.0

.NET Framework 4.5

String interpolation

C# 6.0

.NET Framework 4.6

Tuples

C# 7.0

.NET Framework 4.7

Nullable reference types

C# 8.0

.NET Core 3.0

Records

C# 9.0

.NET 5.0

Global usings

C# 10.0

.NET 6.0

Raw strings

C# 11.0

.NET 7.0

Primary constructors

C# 12.0

.NET 8.0

params collections

C# 13.0

.NET 9.0

Modern C# Checklist (What to Use Now)

Essential (Use Always):

  • Lambda expressions x => x * 2

  • LINQ Where, Select, OrderBy

  • String interpolation $"{name}"

  • Null-conditional ?., ?[]

  • async/await

  • Collection initializers new List<int> { 1, 2, 3 }

Modern (C# 8.0+):

  • Nullable reference types #nullable enable

  • Switch expressions value switch { ... }

  • Indices and ranges [^1], [..]

  • using declarations using var file = ...

Latest (C# 9.0-13.0):

  • Records public record Person(string Name, int Age)

  • Init-only setters { get; init; }

  • Top-level statements (simple programs)

  • Global usings global using System;

  • File-scoped namespaces namespace MyApp;

  • Raw string literals """ ... """

  • Collection expressions [1, 2, 3]

  • Primary constructors class Person(string name)

Legacy (Avoid):

  • System.Tuple (use ValueTuple)

  • Anonymous methods (use lambdas)

  • Old string formatting (use interpolation)


Migration Guide

From Old C# to Modern

Tuples

Anonymous Methods to Lambdas

String Formatting

Null Checking

Switch


When to Use What?

Choose the Right Feature

Need to return multiple values?

  • Use tuples (string, int) for simple cases

  • Use records for complex types

Need immutable data?

  • Use records with init properties

  • Use readonly struct for value types

Need to check for null?

  • Use null-conditional ?.

  • Use null-coalescing ??, ??=

  • Enable nullable reference types #nullable enable

Need pattern matching?

  • Use switch expressions for simple cases

  • Use property patterns for complex conditions

  • Use list patterns for collection matching

Need efficient slicing?

  • Use Span<T> for performance-critical code

  • Use Memory<T> when need to store in fields

Need async sequences?

  • Use IAsyncEnumerable<T> for streaming data

  • Use await foreach to consume


Guide Complete! This comprehensive timeline and feature reference will help you understand C# evolution and use modern features effectively! 📘

Last updated