C# (.NET)
C# is a modern, statically typed language in the .NET ecosystem. Once Windows-only, modern .NET is cross-platform, fast, and production-proven, powering backend services, desktop apps, cloud workloads, and games (via Unity).
Its strengths are excellent tooling (first-class IDE support, debugging, profiling), a mature high-performance runtime, and a coherent, well-designed language that keeps adding modern features (records, pattern matching, nullable reference types). async/await — which C# pioneered — is central to how modern .NET code is written.
TL;DR
- A strong choice for backend APIs and services (ASP.NET Core), plus Unity and desktop.
- Cross-platform and fast; excellent tooling and debugging.
async/awaitis pervasive — use async I/O and never block on it.- Rich type system: classes, records, structs, generics, and LINQ.
Quick Example
A minimal API endpoint returning a record — concise, typed, and fast:
Core Concepts
- The runtime (CLR) — C# compiles to IL, which the .NET runtime JIT-compiles to native code (portable, fast, GC-managed).
- Types —
class(reference),struct(value), andrecord(concise, immutable data — great for DTOs). - Generics — type-safe reusable code (
List<T>,Dictionary<K,V>). - LINQ — declarative querying/transformation over collections (
.Where().Select().OrderBy()). - Exceptions — for error handling; don't use them for expected control flow.
Async & Concurrency
Modern .NET is async-first:
- Use async I/O for network/file calls; never block with
.Result/.Wait()(causes deadlocks). - Pass
CancellationTokens and set timeouts; throttle unbounded parallelism.
Tooling
The dotnet CLI handles build/test/run/publish; NuGet is the package manager.
Best Practices
- Use records for DTOs and value-like data; prefer immutability.
- Async all the way — don't mix sync and async; flow
CancellationTokens. - Use dependency injection (built into ASP.NET Core) over static singletons.
- Don't log sensitive data; validate and authorize at boundaries (see API Security).
Comparison: C# vs Java
See Java.
Common Mistakes
Sync-over-async deadlocks
Unbounded parallelism
FAQ
Is C# only for Windows?
No — that's outdated. Modern .NET (formerly .NET Core) runs on Windows, Linux, and macOS, in containers and the cloud. The legacy .NET Framework was Windows-only, but new development targets cross-platform .NET.
What's a record and when should I use it?
A record is a concise reference (or struct) type with value-based equality and immutability by default — ideal for DTOs, domain values, and anything you compare by content rather than identity. It removes boilerplate (Equals, GetHashCode, with expressions).
Why is .Result/.Wait() dangerous?
Blocking on an async operation can deadlock when a synchronization context is involved (classic in older ASP.NET and UI apps), and it wastes a thread. Use await throughout instead of blocking.
C# or Java?
Both are mature, fast, statically typed languages. C#/.NET fits Microsoft-adjacent stacks, Unity game dev, and teams who like its modern language design. Java/JVM has the larger overall ecosystem and is the Android default. Choose by ecosystem and team familiarity.
Related Topics
- Java — The other major managed-runtime language
- REST API Design — Building APIs with ASP.NET Core
- Authentication — Securing services
- Microsoft Azure — Common .NET deployment target
- Programming Languages — The broader landscape