C# / .NET
This page covers modern C# (C# 12/13) features, keywords, and ecosystem highlights for building apps on .NET.
Keywords & Contextual Keywords
- abstract, add, alias, as, async, await
- base, bool, break, byte
- case, catch, char, checked, class, const, continue
- decimal, default, delegate, dynamic
- do, double, else, enum, event, explicit, extern
- false, file, finally, fixed, float, for, foreach
- global, goto, if, implicit, in, init, interface, internal, is
- lock, long, managed, module, namespace, new, nint, notnull, null
- object, operator, out, override, params, partial, private, protected, public
- readonly, record, ref, required, return
- sbyte, sealed, short, sizeof, stackalloc, static, string, struct, switch
- this, throw, true, try, typeof, uint, ulong, unchecked, unsafe, ushort
- using, value, var, virtual, void, volatile, when, where, while, with, yield
Type System & Memory
- Value types (struct, record struct, tuple) live on the stack or inline.
- Reference types (class, record, interface, delegate) live on the managed heap.
- Generics are reified (no type erasure) and support constraints (`where T : class`).
- Span<T> and Memory<T> provide stack-only and safe slicing of buffers.
- Nullable reference types add compile-time null-safety annotations.
Language Features to Master
- Async/await with Task, ValueTask, and IAsyncEnumerable.
- Pattern matching: switch expressions, relational and logical patterns.
- LINQ for expressive data queries over in-memory or remote providers.
- Records and `with` expressions for immutable data models.
- Top-level statements and file-scoped namespaces for minimal boilerplate.
- Source generators and analyzers for compile-time code generation.
- NativeAOT / ReadyToRun options for deployment.
Operators
- Arithmetic: + - * / % ++ --
- Comparison: == != > < >= <=
- Logical: && || !, bitwise & | ^ ~
- Null-coalescing: ?? and ??=, null-conditional: ?. ?[]
- Assignment: = += -= *= /= %= &= |= ^= <<= >>=
- Pattern operators: is, switch, when clauses.
.NET Runtime & Tooling
- CLR/CORECLR provides JIT, GC, and metadata services.
- SDK CLI: `dotnet new`, `dotnet build`, `dotnet test`, `dotnet publish`.
- Popular frameworks: ASP.NET Core, MAUI, Blazor, Unity (subset), Orleans.
- NuGet manages package dependencies (`dotnet add package`).
- Diagnostics: dotnet-trace, dotnet-counters, PerfView, Visual Studio profiler.
Best Practices
- Favor dependency injection and configuration via Options pattern.
- Use `await using` for async disposable resources (IAsyncDisposable).
- Adopt analyzers (StyleCop, Roslyn) and nullable warnings as errors.
- Prefer records with `init` setters for DTOs.
- Benchmark critical code using BenchmarkDotNet.