Codectionary / Developer documentation / C#

Start here to learn what C# is, where it came from, how it works with .NET, and the different kinds of applications you can build with it.

File extension
.cs
Runs in
.NET runtime

What C# is

C# (pronounced “see sharp”) is a general-purpose programming language developed at Microsoft. General-purpose means that its instructions can solve many kinds of problems: processing data, responding to web requests, drawing an interface or controlling a game. A C# program can use variables, decisions, loops and methods to express those instructions.

C# is statically typed: the compiler knows the type of a variable or expression before the program runs and can report many incorrect operations early. It is also designed around readable, structured source code and a large library ecosystem. C# source files usually end in .cs; to run most applications you also need a compatible runtime and libraries, commonly supplied by .NET.

How C# began and evolved

Microsoft developed C# during the creation of the .NET Framework. Anders Hejlsberg was its chief designer, working with a wider Microsoft team. The language was intended to make it productive to build applications for the new .NET platform while keeping familiar C-family syntax and adding strong typing, object-oriented tools and managed-runtime support.

Microsoft released the first widely distributed C# implementation in July 2000 as part of its .NET initiative. The C# version history dates the 1.0 language release to January 2002; .NET Framework 1.0 and Visual Studio .NET followed in February 2002. These dates refer to different milestones, not three separate origins of the language.

The language did not stop at its original class-and-interface model. Later releases added generics for reusable typed code, LINQ for querying data, async and await for asynchronous work, pattern matching for clearer branching and records for data-focused types. The language and .NET now have open-source development, but a project can only use features supported by its chosen compiler and libraries.

C# is the language; .NET is the platform

Think of C# as the rules for writing a program and .NET as a platform that provides tools, an execution environment and reusable libraries. You write C# source; the .NET SDK can build it; the .NET Runtime can execute a typical managed application. Other languages, including F# and Visual Basic, can also use .NET. Learning C# syntax and learning a particular .NET framework are related but different jobs.

The table separates names that often appear together in a tutorial. You do not need to memorise every acronym now: the useful first distinction is that an SDK is for creating and building an app, while a runtime is for running one. Installing a .NET SDK includes a corresponding runtime; a machine that only runs a framework-dependent app may need an appropriate runtime but not the full SDK.

NameWhat it doesBeginner example
C#Programming language: defines the syntax and meaning of your source code.A .cs file contains Console.WriteLine("Hello");
.NETDevelopment platform: brings together languages, tools, runtimes and libraries.A .NET console project builds and runs C# code.
.NET SDKSoftware Development Kit: command-line tools, compiler, templates and other build tools.dotnet new creates a project; dotnet build builds it.
.NET RuntimeComponents needed to execute a compatible managed .NET application.A deployed app runs with an appropriate installed or bundled runtime.
CLRCommon Language Runtime: the managed execution engine in the .NET Runtime.It loads code and provides services such as garbage collection.
C# compilerChecks C# code and normally emits an assembly containing IL and type metadata.A type error can stop the build before the app runs.
ILIntermediate Language: platform-neutral instructions in a typical compiled .NET assembly.The runtime uses IL as input for native-code compilation.
JITJust-in-time compilation: turns needed IL into native machine code while an app runs.A method can be compiled when the runtime first needs it.
Standard librariesReusable APIs supplied by the platform for common work.System.Console writes text; collections hold data.

From C# source code to a running program

For a typical modern .NET console application, the path below explains what dotnet run does behind the scenes. An assembly is a compiled file containing code and metadata; metadata describes the types and references the runtime needs. IL is not the same as the machine instructions executed directly by a CPU.

The CLR also provides services such as garbage collection, exception handling and type information while managed code runs. Garbage collection reclaims managed objects that are no longer reachable; it does not automatically close a file or network connection at the right time. Standard libraries supply useful APIs, but calling a library method is still part of your program’s execution, not a separate programming language.

This is the common path, not a universal rule for every C# app. For example, Native AOT publishing first compiles IL to platform-specific native code; that app does not use a JIT when it starts. AOT has compatibility limits and needs a target platform, so it is a deployment choice rather than a beginner setting to turn on for every project. Unity and other hosts can have their own build and execution pipelines.

  1. Write C# statements in a .cs file inside a project. Its project file selects a target framework and build settings.
  2. Use the .NET SDK with dotnet build, or dotnet run, which builds if necessary. The C# compiler checks syntax and types and reports errors before a successful build.
  3. For the usual managed build, the compiler produces an assembly with IL and metadata. This is an intermediate form, not source code or final CPU instructions.
  4. At launch, the appropriate .NET Runtime loads the assembly and its dependencies. Its CLR provides the managed execution environment.
  5. Normally, the JIT compiles IL for needed methods into native instructions, which the CPU executes. The app can then call standard-library APIs such as Console.WriteLine and produce output.

Modern .NET and .NET Framework are different

The original .NET Framework is the older, Windows-only product line used by many existing applications. Modern .NET grew from .NET Core and continues as the cross-platform .NET 5-and-later line. Both can run C# programs, but they have different runtimes, target frameworks, project conventions and sets of available APIs. A program targeting .NET Framework does not automatically become a modern .NET app just because both use the word “.NET”.

Modern .NET can target Windows, macOS and Linux where the relevant runtime and libraries are supported. That does not make every .NET application cross-platform: Windows Forms and WPF, for example, remain Windows desktop technologies. When maintaining an older .NET Framework project, check its framework-specific libraries and platform APIs before porting it. Some APIs and third-party packages require changes or have no direct replacement; migration needs testing rather than a simple label change.

ASP.NET Core, .NET MAUI and other frameworks build on particular .NET capabilities for different kinds of applications. Unity uses C# too, but has its own engine APIs and supported scripting environment. Choose tools for the application you are building instead of assuming every C# workflow uses an identical runtime.

Objects, methods and other programming styles

Object-oriented programming (OOP) groups related data and behaviour into types. For example, an Order class might store items and provide a CalculateTotal method. An object is an instance of that class: one particular order with its own data. Encapsulation keeps an object’s internal state behind a clear public interface; inheritance and interfaces can help types share or promise behaviour where they genuinely fit.

You do not need to put every calculation into a deep class hierarchy. C# also supports procedural code organised into methods, functional-style expressions and lambdas, LINQ queries over collections, immutable records, and asynchronous code using async and await. A small console program can even start with top-level statements rather than an explicit Program class. Use the style that makes the task easiest to understand and maintain.

How C# differs from C and C++

C#, C and C++ share familiar braces, semicolons and control-flow words such as if and for. Their names and surface syntax do not make them interchangeable languages. A C program is normally compiled directly to native machine code and often requires explicit memory management. C++ supports classes and many programming styles, with fine-grained control over memory and object lifetimes. Typical C# applications instead compile for a managed runtime and use garbage collection for ordinary objects.

C# also has its own type system, syntax, standard libraries and project tools. A C or C++ header cannot simply be pasted into a C# project and compiled. C# can interoperate with native code when needed, but that is a separate technique with extra complexity. If you are learning C#, start with C# examples rather than treating it as a renamed C or a simplified C++.

What people build with C#

Desktop applications: Windows Forms and WPF are established options for Windows interfaces. .NET MAUI is a different toolkit for apps targeting supported mobile and desktop platforms. A team building an inventory tool might choose one of these depending on its devices and UI needs.

Web applications, backend services and APIs: ASP.NET Core can render websites, expose JSON endpoints and run background services. An online shop could use a C# API to validate an order and store it in a database. A browser may still use HTML, CSS and JavaScript for the user interface; C# on the server does not automatically replace them.

Games: Unity uses C# scripts to respond to game events and control behaviour such as movement or scoring. Unity supplies its own engine APIs and supported C# environment, so a Unity script is not the same project setup as an ASP.NET Core service.

Cloud and automation: .NET services can run on cloud infrastructure to process messages, schedule work or expose endpoints. A small C# console tool can rename files or transform a report. Cloud hosting and automation require their own permissions, deployment choices and libraries; they are applications of C#, not separate versions of the language.

Mobile and cross-platform applications: .NET MAUI lets developers share C# code across supported Android, iOS, macOS and Windows app targets while accessing platform features. The UI and packaging still have platform-specific requirements; “cross-platform” does not mean every framework runs unchanged everywhere.

Why choose C#—and when to pause

C# offers compile-time checking, expressive language features, mature tooling, extensive .NET libraries and several application frameworks. Those strengths are useful when maintaining a service with many endpoints, sharing code across a team or building a desktop tool that will grow over time. Managed memory and async tools can remove common chores, though they do not guarantee a bug-free application.

There are tradeoffs. You need to learn both language concepts and the relevant framework; a small script can still require project and SDK setup. Runtime size, startup behaviour, deployment requirements and platform-specific APIs matter in some environments. Unity’s supported language and APIs may differ from a current general .NET project. C# is not automatically the best choice for browser-only scripts, very constrained systems or a codebase whose team and tooling already fit another language. Choose for the project’s needs, not because one language wins every category.

Your first C# program

The example below prints a greeting and then a calculated total. First follow the .NET SDK installation guide for your operating system, then create a console project using the terminal commands below. Replace its Program.cs contents with the example and run dotnet run from the project folder. The SDK builds the code before launching it. This is a console program: its output appears in the terminal, not in a webpage.

The first line stores a name in a string variable. The next two lines hold whole-number prices and add them. Console.WriteLine writes a line of output; the $ before the quoted text enables string interpolation, so {name} and {total} are replaced by their values. Semicolons end each statement. The program prints Hello, Sam! and Total: 12. Top-level statements keep the first example small; the compiler supplies the entry-point structure that older tutorials write explicitly.

Codectionary’s Playground can display and edit C# source, but it does not currently execute C# or provide a .NET runtime. Run this example in a local .NET console project instead. Later, change one price or the name and predict the output before running it again.

Terminal — create and enter a console project

dotnet new console -n FirstCSharp
cd FirstCSharp

Terminal — after saving Program.cs

dotnet run

Where to go next

Start with variables and data types, then console output, decisions and loops. When those are comfortable, learn methods, classes and collections. LINQ and async programming make more sense once you have ordinary collections and methods to work with. Pick a framework such as ASP.NET Core, Unity or .NET MAUI after you know what you want to build; each has its own setup and APIs.

A practical first project is a small command-line expense tracker: read a few amounts, total them and print the result. It exercises core C# without requiring a web server or game engine. Return to the reference guides as questions arise rather than trying to memorise the whole language at once.

Syntax

Console.WriteLine("Hello, world!");

Examples

Print a greeting and a total

A complete Program.cs for a modern .NET console project using top-level statements.

string name = "Sam";
int notebookPrice = 8;
int penPrice = 4;
int total = notebookPrice + penPrice;

Console.WriteLine($"Hello, {name}!");
Console.WriteLine($"Total: {total}");
  1. Create a console project with the .NET SDK, replace Program.cs with this code, then run dotnet run in the project folder. The output is Hello, Sam! followed by Total: 12.
  2. string stores the name as text. Each int stores a whole number. The + operator adds the two prices and stores 12 in total; no input is needed for this first example.
  3. Console.WriteLine prints each interpolated string on its own line. The $ makes the expressions in braces evaluate and appear in the output. This pattern is useful for reports or command-line tools that present calculated results.

C#: background & uses

Used for
.NET web APIs, Desktop applications, Unity games
Created by
Anders Hejlsberg and the Microsoft team
First released
2002 · version 1.0 (announced in 2000)
Version / standard
C# 14

Current stable language release. Availability depends on your .NET SDK.

In the real world

Facts checked 8 September 2026. Product links describe documented uses.

Best practices

  • Learn core C# syntax separately from the APIs of a particular framework or game engine.
  • Use a .NET console project for the first program; install a compatible SDK before expecting dotnet run to work.
  • Treat compiler feedback as a chance to correct a type or syntax mistake before running the program.
  • Choose a desktop, web, game or mobile framework after deciding what your application needs to do.

Runtime & versions

.NET runtime. Feature availability depends on the language and runtime version used by your project; consult the official reference below.

C# language reference

Specifications & further reading