C# started out as the language for a new Windows development platform. Today the same language runs web services on Linux, desktop apps on Windows and macOS, Unity games, phone apps, command-line tools, and programs compiled ahead of time into native binaries. I write C# for a living, and that range still surprises me a little when I think about where it began.
It got there through twenty-odd years of changes to the language, the compiler, the runtime and the libraries, and eventually to who gets to watch and influence the design. There was never a big rewrite. Some releases are remembered for their syntax. The ones that mattered most often changed something underneath it.
Before C#: a new platform needed a new language
In the late 1990s, writing software for Windows meant choosing between native C++, Visual Basic and COM, with a web platform growing up alongside them. Meanwhile Java had shown developers what a managed runtime felt like: garbage collection, portable bytecode, far fewer ways to corrupt memory. Microsoft needed a single platform that offered the same things, and a language designed for it.
In 1999 a team under Anders Hejlsberg began work on that language. Hejlsberg had already written Turbo Pascal and led the design of Delphi. Internally the project was called Cool, usually explained as "C-like Object Oriented Language". It kept the braces and control flow of the C family and added garbage collection, metadata, properties, delegates, exceptions and a unified type system.
The name didn't make it to release. Microsoft announced the language as C# in 2000, together with .NET. The sharp sign hints at a step up from C++, the way a sharp raises a note in music.
C# was never designed as a language alone, and that explains a lot of what came later. The language, the Base Class Library, the Common Language Runtime and the metadata format were all drawn up together as one platform. As a result, a C# feature may depend on a compiler trick, on runtime support, on a library API, or on all three, and much of the language's history is about which of those layers did the work.
2002: C# 1.0 establishes the foundation
C# 1.0 shipped with Visual Studio .NET 2002 and .NET Framework 1.0. Most of what still makes the language recognisable was there on day one:
- Classes, interfaces, structs, and enums.
- Properties, indexers, events, and delegates.
- Attributes and runtime metadata.
- Exceptions, and deterministic cleanup with
using. - Garbage collection, with unsafe code available when you needed it.
- One type system in which value types and reference types both derive from
object.
public sealed class TemperatureSensor
{
private decimal _celsius;
public event EventHandler ThresholdReached;
public decimal Celsius
{
get { return _celsius; }
}
public void Record(decimal value)
{
_celsius = value;
EventHandler handler = ThresholdReached;
if (value >= 80 && handler != null)
handler(this, EventArgs.Empty);
}
}
I wrote that example the way you'd have written it in 2002. The event is
copied to a local variable before the null check, which was the standard idiom
for years because another thread could unsubscribe between the check and the
call. These days you'd write ThresholdReached?.Invoke(this,
EventArgs.Empty). Everything else in the class would pass a code review
today, and I think that says a lot about how well the original design has held
up.
Microsoft also submitted C# and the Common Language Infrastructure to ECMA. The first standard, ECMA-334, was approved in 2001, and ISO followed in 2003. Microsoft's compiler was still the one that mattered, but on paper the language now existed independently of it.
The managed execution model
C# source doesn't normally compile to machine code. It compiles to Common Intermediate Language (CIL) plus metadata describing every type. The Common Language Runtime loads that assembly and turns the CIL into native code, either just in time while the program runs or ahead of time.
Splitting the work this way paid off for a long time:
- Several languages could target one runtime and share its libraries.
- Assemblies described their own types, so tools could inspect them.
- The runtime handled memory, exceptions, threads and code generation.
- The compiler could add syntax by translating it into things the runtime already understood.
- A better JIT made existing binaries faster without anyone recompiling them.
It also created a tension that has never gone away. When a feature needs the runtime to change, it's slower and riskier to ship than one the compiler can fake. So for every proposal, somebody has to decide where it should live.
2005: generics make the type system scale
C# 2.0 arrived with Visual Studio 2005 and .NET Framework 2.0, and its
headline feature was generics. Before them, a general-purpose collection
stored everything as object. You cast on the way out, and every int you
put in was boxed onto the heap. Generics made the element type part of the
API:
public static TBuilder AddServiceDefaults<TBuilder>(this TBuilder builder)
where TBuilder : IHostApplicationBuilder
(That signature is from a project of mine, in the startup code that the Aspire
template generates. The extension-method syntax around it came later. The type
parameter and its where constraint are straight from 2005.)
The decision that mattered was to put generics into the runtime. Java added
them at about the same time and erased the type information during
compilation. The CLR keeps it. It knows that a List<int> is a different type
from a List<string>, and it generates specialised code for value types so
nothing gets boxed. That choice cost Microsoft a runtime change, and it has
paid for itself ever since. Span<T> and generic math, among other things,
wouldn't work without it.
C# 2.0 also brought nullable value types, iterators with yield return,
anonymous methods and partial types. Iterators set a pattern that later
releases kept reusing: you write something short, and the compiler rewrites it
into a state machine you'd never want to write by hand.
2007: LINQ changes how C# expresses data work
C# 3.0 is the most interesting release to look back on, because nearly every feature in it existed to make one thing possible. That thing was Language Integrated Query, and it needed all of these:
- Lambda expressions.
- Extension methods.
- Expression trees.
- Anonymous types.
- Object and collection initializers.
- Local variable type inference with
var. - Query expression syntax.
var dropOffs = sessions
.Where(s => started.Contains(s.Key) && !completed.Contains(s.Key))
.Select(s => s
.Where(e => e.Kind == WidgetEventKind.StepAdvance && e.StepKey != null)
.OrderByDescending(e => e.OccurredAt)
.Select(e => e.StepKey!)
.FirstOrDefault() ?? FirstScreenKey)
.GroupBy(key => key)
.OrderByDescending(g => g.Count())
.ThenBy(g => g.Key)
.FirstOrDefault();
That's real code from my analytics. It works out which step of a form people most often abandon: take the sessions that started and never finished, find the last step each one reached, group by step, and pick the biggest group. Written with loops and dictionaries it would be thirty lines.
Here sessions is a list in memory, so each lambda compiles to a delegate and
runs as ordinary code. Elsewhere in the same project the same operators are
applied to an IQueryable<T>. There the lambdas compile to expression trees,
which are data structures describing the code, and Entity Framework walks
those trees and turns them into SQL.
LINQ's influence went well beyond databases. Lambdas, extension methods and
fluent method chains became the normal way to write C#, and most libraries
published since then assume you're comfortable with them. Query syntax (from
c in customers where ...) is far less common now than method chains. The
pieces that were built to support it turned out to matter more than the syntax
did.
2010: interoperability becomes more practical
C# 4.0 was the practical release. Its main addition was the dynamic type,
which postpones member lookup until runtime. If you ever automated Office
through COM before it existed, you'll remember why it was welcome.
dynamic worksheet = excel.Worksheets[1]; worksheet.Cells[1, 1].Value = "Quarter";
Named and optional arguments arrived in the same release, and for much the
same reason: COM APIs loved methods with fifteen parameters. Generic
covariance and contravariance meant an IEnumerable<string> could finally be
passed where an IEnumerable<object> was expected.
Some people worried that dynamic meant C# was giving up on static typing. It
didn't work out that way. dynamic stayed at the edges, where code talks to
something that really is dynamic, and most C# developers go months without
typing the word.
2012: async/await reframes asynchronous code
If I had to pick the single most influential C# feature, it would be async
and await from C# 5.0. Asynchronous APIs existed before that, but using them
meant callbacks or hand-chained tasks, and the logic of a method ended up
scattered across several of them. With await you could write the code top to
bottom again and still not block a thread.
public static async Task<Widget> RequireOwnedAsync(
this IQueryable<Widget> widgets,
string userId,
Guid widgetId,
CancellationToken cancellationToken)
{
var widget = await widgets
.OwnedBy(userId)
.FirstOrDefaultAsync(w => w.Id == widgetId, cancellationToken);
Guard.Against.NotFound(widgetId, widget);
return widget;
}
That's a helper from my own code. It loads a record and makes sure it belongs
to the signed-in user. No thread sits waiting at the await while the
database answers. The compiler rewrites the method into a state machine. When
the method reaches an await on something that hasn't finished, it saves its
local variables, returns to the caller, and arranges to be resumed when the
operation completes.
The CancellationToken parameter is the part the language didn't solve.
Nothing passes it along for you. Every async method in the project takes one
and hands it to the next call, and there are still a couple of places where
the chain gets dropped.
JavaScript, Python, Rust and Swift all adopted some version of this later. C# didn't invent the underlying idea, but it made the idea easy enough that ordinary application code could use it everywhere, and that turned out to be what other languages wanted to copy.
2014-2016: Roslyn and .NET move into the open
For its first ten years or so, the C# compiler was a closed box written in C++. Source code went in and an assembly came out. Roslyn was a complete rewrite of the compiler in C# itself. Microsoft released it as open source in 2014, and development later moved to GitHub.
The licence was only part of the change. Roslyn exposes its own internals as an API: syntax trees, the semantic model, diagnostics. An editor, an analyzer or a refactoring tool can ask the real compiler what a piece of code means. Before Roslyn, each of those tools had to carry its own approximation of the language.
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public sealed class ApiAnalyzer : DiagnosticAnalyzer
{
public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.RegisterSyntaxNodeAction(AnalyzeMethod, SyntaxKind.MethodDeclaration);
}
}
.NET itself was changing in the same years. The .NET Foundation was set up in 2014 and the core runtime was open-sourced. In 2016, .NET Core 1.0 shipped for Windows, Linux and macOS.
Anyone who started with .NET after 2016 may not realise how big a shift this was. Before it, C# on a Linux server meant Mono, and plenty of companies wouldn't consider it. Afterwards it was a supported and unremarkable deployment target. The design process opened up as well. Language proposals, the notes from design meetings and the compiler's pull requests are all public now, and outsiders regularly contribute fixes.
C# 6 and 7: faster, more incremental evolution
With Roslyn in place, adding language features got much cheaper, and the
releases show it. C# 6 in 2015 had no headline feature. It was a collection of
small things that made everyday code nicer: string interpolation, the ?.
operator, nameof, expression-bodied members, exception filters.
C# 7 and its point releases added tuples, deconstruction, local functions,
out variables, ref returns, the language support that Span<T> needed, and
the first version of pattern matching.
private static bool IsPermanentStatus(SmtpStatusCode status) => status switch
{
// A full mailbox is the canonical recoverable rejection: the recipient
// empties it and mail flows again. Suppressing that address forever
// over a temporary condition would be the wrong trade.
SmtpStatusCode.ExceededStorageAllocation => false,
SmtpStatusCode.MailboxNameNotAllowed
or SmtpStatusCode.MailboxUnavailable
or SmtpStatusCode.UserNotLocalTryAlternatePath => true,
_ => (int)status is >= 500 and < 600,
};
That's from the code in my app that decides whether a bounced email should
ever be retried, and it shows pattern matching as it looked a few releases
later. In C# 7 you got type patterns in is and switch and not much else.
The switch expression arrived in C# 8. The or patterns and the relational
>= 500 and < 600 arrived in C# 9. I think this is a good illustration of how
the team works now. They ship a small core, see how people use it, and extend
it in a way that doesn't break what's already there.
2019: nullable references confront a historic problem
Tony Hoare called the null reference his "billion-dollar mistake". C#
inherited it in full: any reference type could be null, the type system said
nothing about it, and NullReferenceException became the exception every C#
developer knows by heart. By 2019 there were millions of existing programs, so
the meaning of string couldn't simply be changed.
C# 8 got around this with an opt-in analysis. Once it's switched on, string
means "shouldn't be null" and string? means "might be". The compiler follows
the flow of your code and warns you when you dereference something that could
be null.
#nullable enable
public static int LengthOrZero(string? value)
{
if (value is null)
return 0;
return value.Length;
}
Nothing changes at runtime. A string? and a string are the same type as
far as the CLR is concerned, and the annotations are only metadata for the
compiler. That makes it a weaker guarantee than Kotlin or Swift give you. It's
also the only reason an old library could adopt the feature gradually without
breaking the code that called it.
The analysis has limits, and there's one in the LINQ example further up. Look at these two lines again:
.Where(e => e.Kind == WidgetEventKind.StepAdvance && e.StepKey != null) // ... .Select(e => e.StepKey!)
The Where has just filtered out every null StepKey. A person reading it
can see that. The compiler can't, because its flow analysis works inside one
method body and those are two separate lambdas. So the Select needs a ! to
say "trust me". I have nullable warnings switched on as errors across the
whole solution, so the compiler makes me write that ! every time this comes
up.
C# 8 also added async streams, ranges and indices, switch expressions, and default interface methods.
2020 and beyond: C# joins the annual .NET rhythm
.NET 5 put an end to the split between .NET Framework and .NET Core. Since then there has been a new .NET every November and a new C# version with it:
| Version | Year | Representative additions |
|---|---|---|
| C# 9 | 2020 | Records, init-only setters, top-level statements |
| C# 10 | 2021 | Global usings, file-scoped namespaces, record structs |
| C# 11 | 2022 | Required members, raw strings, generic math, list patterns |
| C# 12 | 2023 | Primary constructors, collection expressions |
| C# 13 | 2024 | Params collections, new lock semantics, ref safety updates |
| C# 14 | 2025 | Extension members, field-backed properties, null-conditional assignment |
Records are the feature from these years that I use constantly. A record is
still an
ordinary .NET class, but the compiler writes value equality, a readable
ToString and non-destructive copying for you. This is from the pricing code
in EstimateFlow, the app I work on. It needs to ask "what would this job cost
if the customer had also ticked this option?" without touching the customer's
real answers:
var selections = new Dictionary<string, IReadOnlyList<string>>(answers.Selections)
{
[step.Key] = [.. selected, option],
};
return (answers with { Selections = selections }, risk.Label(option));
Three eras of the language are in those five lines. The with expression
copies a record and changes one property (C# 9). [.. selected, option] is a
collection expression with a spread (C# 12). And the method returns a tuple,
which goes back to C# 7.
Primary constructors, also from C# 12, are the other recent feature I lean on. EstimateFlow has 112 types declared that way. A class that used to open with a constructor and four lines copying parameters into fields now looks like this:
public sealed class WidgetInstallRecorder(
IServiceScopeFactory scopeFactory,
TimeProvider timeProvider,
ILogger<WidgetInstallRecorder> logger) : BackgroundService, IWidgetInstallRecorder
Raw string literals from C# 11 turned out to be more useful than I expected.
The script that contractors embed on their sites is JavaScript generated by a
C# endpoint, and it's written as one $$""" string. With two dollar signs, a
single pair of braces is literal text, so the JavaScript reads normally, and
{{value}} is where C# interpolates.
I haven't used anything from the last two rows of that table. The project
targets .NET 10 and sets no language version, so it compiles as C# 14. I
searched it for C# 13 and 14 features and found none. There's no field
keyword, no extension members, and no params collections. List patterns from
C# 11 aren't in there either. The newest things I actually write are from
I don't think that's unusual. A feature has to solve a problem I have before I'll go and learn its syntax, and the last two releases have mostly solved problems for people who write libraries.
The other direction of travel has been downward, towards the machine.
Span<T>, Memory<T>, ref structs, function pointers, native-sized integers,
generic math and Native AOT all let C# do work that used to mean dropping into
C++.
How a C# feature becomes real
The design work happens in public, mostly in the dotnet/csharplang
repository on GitHub. A feature usually goes through these stages:
- Somebody describes a problem and sketches a possible design.
- A written proposal pins down the syntax and semantics.
- The language design meetings argue through the trade-offs. The notes are published.
- Roslyn implements the compiler behaviour and the diagnostics.
- Runtime or library changes land, if the feature needs them.
- Tooling, documentation and analyzers catch up.
Most ideas never get through. There's an old rule on the C# team, usually credited to Eric Gunnerson, that every feature starts at minus 100 points. Being a good idea isn't enough. A feature has to be good enough to repay the cost of designing it, implementing it, testing it, documenting it and teaching it, and then of living with it forever, because features are almost never removed.
Compatibility is the hardest constraint of all. Anything new has to coexist
with twenty years of existing source code, compiled libraries, reflection
tricks, overload resolution rules and tools that make assumptions about
syntax. It's why some features look slightly awkward. The field keyword, for
example, took several releases to ship, partly because people already had
variables named field.
The ideas that stayed constant
A few principles have held from 1.0 to today:
- C# is object-oriented, functional, imperative, occasionally dynamic and occasionally low-level. It takes whatever works.
- Tooling counts as part of the language. Features are designed with IntelliSense, refactoring and debugging in mind.
- Old code nearly always keeps compiling, and you adopt new things when you're ready.
- Properties, LINQ, async/await, patterns and records all exist to make frequent things short and obvious.
- The runtime keeps you safe unless you explicitly ask it not to.
The price of all this is size. One codebase can contain classes written in 2002 style, query syntax from 2007, async streams from 2019 and records from 2020, and a newcomer has to be able to read every one of them. I think that's a real downside. In exchange, nobody ever had to throw their code out and start again. Compare that with what the move from Python 2 to 3 cost its community, and I think C# made the better trade.
What C#'s history teaches
Nobody in 1999 predicted cloud services on Linux or phones or Native AOT, and C# 1.0 wasn't designed for any of them. The language got there because the platform could change underneath it. Generics went into the runtime. LINQ gave everyone a shared vocabulary for working with data. Async/await made non-blocking code readable. Roslyn opened up the compiler, .NET Core opened up the operating systems, and nullable analysis patched a twenty-year-old hole without breaking a single existing binary.
The basic offer hasn't changed since Project Cool. You get productive, strongly typed code on a managed runtime, and a way down to the machine when you need it. A program written in 2002 has a decent chance of compiling today, and I can't think of many languages from that era that can say the same.
