About C#

C# is a statically typed, general-purpose language created at Microsoft by a team led by Anders Hejlsberg. Version 1.0 shipped with the .NET Framework in 2002. Today it is open source, developed in public on GitHub, and runs on Windows, Linux and macOS through .NET.

Your C# source is compiled by Roslyn into intermediate language (IL). At run time the .NET runtime turns that IL into machine code, either just in time or ahead of time with Native AOT. Memory is managed by a garbage collector, so you rarely free anything by hand, but the language still gives you low-level tools such as Span<T>, stackalloc and pointers when performance calls for them.

Where C# is used

  • Web APIs and sites with ASP.NET Core
  • Desktop applications with WinForms, WPF, WinUI and .NET MAUI
  • Games, mostly through Unity
  • Cloud services, background workers and command-line tools
  • Mobile apps through .NET MAUI

How the language has changed

The C# many developers learned in the 2000s looks quite different from current code. Generics arrived in C# 2, LINQ and lambdas in C# 3, async and await in C# 5. More recent versions added records, pattern matching, nullable reference types, top-level statements, primary constructors and collection expressions. The examples on this site use current syntax and call out when something needs a particular version.

Using this site

Every example on csharpexamples.com is a short, focused answer to one task, with code you can paste into a project and an explanation of the parts that tend to go wrong. If you are starting out, follow the Learn C# path. If you are preparing for a job interview, the C# interview questions and answers page covers what is asked most often. To browse everything, see all posts.

The official C# documentation on Microsoft Learn is the reference for the language itself.