Safekipedia

C Sharp (programming language)

Adapted from Wikipedia ยท Adventurer experience

New C Sharp 2023 logo.

C# is a general-purpose programming language that lets you write code in many different ways. It works with many kinds of programming styles, including ones that use objects and classes, and others that use functions.

The main creators of C# were Anders Hejlsberg, Scott Wiltamuth, and Peter Golde from Microsoft. C# was first released to the public in July 2000. After that, it became an international standard. Microsoft made C# together with the .NET Framework and Microsoft Visual Studio.

Over time, Microsoft made many tools for C# free to use on different kinds of computers. This helped programmers all over the world use C#. The latest stable version of C# as of November 2025 is C# 14.

Design goals

C# was created to be a simple and modern programming language. It helps developers write strong and reliable code. The language checks for mistakes, like using variables before they are set, and cleans up unused memory to keep programs safe.

C# works well for building many types of software, from big applications on full computers to small programs on simple devices. It is easy to move between different computers and systems. While C# uses memory and processing power wisely, it does not try to match the speed of older, more complex languages.

History

During the creation of the .NET Framework, a team at Microsoft started building a new programming language called COOL, short for "C-like Object Oriented Language". This language was later renamed to C#.

The main designer of C# was Anders Hejlsberg, who also helped create tools like Turbo Pascal, Delphi, and Visual J++. He wanted C# to avoid problems in older languages like C++, Java, and Delphi.

C# has changed a lot since it began. It now has features that make writing programs easier, like LINQ, which helps organize and find information. Over time, C# has grown to better meet the needs of programmers.

C#
version
Language specificationDate.NETVisual Studio
EcmaISO/IECMicrosoft
1.0ECMA-334:2003, December 2002ISO/IEC 23270:2003, April 2003January 2002January 2002.NET Framework 1.0Visual Studio .NET 2002
1.1
1.2
October 2003April 2003Visual Studio .NET 2003
2.0ECMA-334:2006, June 2006ISO/IEC 23270:2006, September 2006September 2005November 2005Visual Studio 2005
Visual Studio 2008
3.0NoneAugust 2007November 2007
.NET Framework 2.0 (Except LINQ)
.NET Framework 3.0 (Except LINQ)
Visual Studio 2008
4.0April 2010April 2010Visual Studio 2010
5.0ECMA-334:2017, December 2017ISO/IEC 23270:2018, December 2018June 2013August 2012Visual Studio 2012
Visual Studio 2013
6.0ECMA-334:2022, June 2022NoneDraftJuly 2015
.NET Core 1.0
.NET Core 1.1
Visual Studio 2015
7.0ECMA-334:2023, December 2023ISO/IEC 20619:2023, September 2023Specification proposalMarch 2017Visual Studio 2017 version 15.0
7.1Specification proposalAugust 2017
.NET Core 2.0
Visual Studio 2017 version 15.3
7.2Specification proposalNovember 2017Visual Studio 2017 version 15.5
7.3Specification proposal Wayback MachineMay 2018
.NET Core 2.1
.NET Core 2.2
Visual Studio 2017 version 15.7
8.0NoneSpecification proposalSeptember 2019
.NET Core 3.0
.NET Core 3.1
Visual Studio 2019 version 16.3
9.0Specification proposalNovember 2020
.NET 5.0
Visual Studio 2019 version 16.8
10.0Specification proposalNovember 2021
.NET 6.0
Visual Studio 2022 version 17.0
11.0Specification proposalNovember 2022
.NET 7.0
Visual Studio 2022 version 17.4
12.0Specification proposalNovember 2023
.NET 8.0
Visual Studio 2022 version 17.8
13.0Specification proposalNovember 2024
.NET 9.0
Visual Studio 2022 version 17.12
14.0Specification proposalNovember 2025
.NET 10.0
Visual Studio 2026 version 18.0

Syntax

Main article: C# syntax

See also: Syntax (programming languages)

C# has a style of writing code that is similar to other languages like C, C++, and Java. In C#, each line of code ends with a semicolon. Curly brackets group lines of code together, like putting them into boxes. You can give values to variables using an equals sign and compare them using two equals signs next to each other. Square brackets help you work with lists, called arrays, by showing where to find a specific item in the list. Words like "class," "int," and "void" help set up big parts of a program.

Distinguishing features

See also: Comparison of C# and Java

C# has many special features that make it different from other languages like C, C++, and Java.

Portability

C# is designed to work with a system called the Common Language Infrastructure (CLI). This means C# can run on many different computers and operating systems. C# can create many kinds of code.

Typing

C# has strong typing, meaning it checks the types of data you use. For example, it has a special type called bool for true or false values. C# stops you from mixing numbers and true/false values by accident.

Metaprogramming

Metaprogramming lets you write code that can change or look at other code. C# supports this in several ways:

  • Reflection: This lets your program look at and use types and methods while it is running.
  • Expression trees: These let you show code as data, which can be looked at or changed while the program runs.
  • Attributes: These are special tags you can add to code to give it extra information.
  • The .NET Compiler Platform (Roslyn): This lets you work with code while it is being compiled.
  • Source generators: These let you make new code during compilation.

Methods and functions

In C#, a method is a part of a class that can do something, like add numbers. Methods can get and give back values in different ways. C# also lets you add new methods to classes using extension methods.

Properties

C# lets you add properties to classes. Properties are like special methods that can get or set values. Since version 3.0, C# has a simpler way to create properties called auto-implemented properties.

Namespaces

Namespaces help organize code by grouping related parts together. In C#, you can use the using statement to bring in code from other namespaces easily.

Memory access

In C#, most of the time you don't have to worry about memory because the system handles it for you. But you can use special "unsafe" blocks if you need to work with memory addresses directly. The system also cleans up unused memory automatically.

Exceptions

C# has a way to handle mistakes in your code called exceptions. You can use a try-catch block to catch these mistakes and decide what to do instead. There is also a finally block that always runs, no matter what happens.

Polymorphism

C# supports polymorphism, which means you can write code that works with many different types in a similar way. C# does not let a class inherit from more than one other class, but it can use many interfaces. C# also supports overloading methods and operators, and since version 2.0, it supports generic types.

Language Integrated Query (LINQ)

C# has a special feature called LINQ that lets you search and work with data in many places, like databases or lists. LINQ makes it easier to sort and work with data.

Functional programming

C# adds more functional programming features over time. These include:

Common type system

C# uses a unified type system called the Common Type System (CTS). This means all types, even basic ones like numbers, are versions of a main class called System.Object. For example, every type can use a method named ToString().

The CTS divides data types into two groups: reference types and value types. Value types, like numbers and dates, always have a default value and compare by what data they hold. Reference types, like strings and arrays, are unique to each piece and compare by their identity unless special rules are added. Both types can be expanded with types made by users.

Boxing changes a value type into a reference type, and this happens automatically. Unboxing changes it back, but you must tell the computer exactly what type to change it to. For example:

int foo = 42;         // Value type.
object bar = foo;     // foo is boxed to bar.
int foo2 = (int)bar;  // Unboxed back to value type.

Libraries

The C# specification explains the basic types and class libraries the compiler needs. C# is usually used with the Common Language Infrastructure, a standard called ECMA-335 Common Language Infrastructure (CLI).

Besides the standard CLI, many extra libraries are made by companies and communities. These add more features to the .NET framework. C# can use any library listed in the List of .NET libraries and frameworks.

Examples

Hello World

Here is a very simple C# program, a version of the classic "Hello World" example:

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

This code will show the words "Hello, World!" on the screen.

Generics

Generics is a feature that helps developers create better programs. It lets them work with data in a safer way. With generics, developers can create data structures that know what kind of data they hold. This makes the programs run faster and be easier to maintain.

Example

public class DataStore
{
    private T[] items = new T;
    private int count = 0;

    public void Add(T item)
    {
        items[count++] = item;
    }

    public T Get(int index)
    {
        return items[index];
    }
}

Standardization and licensing

In 2001, Microsoft, Hewlett-Packard, and Intel worked together. They sent the rules for C# and the Common Language Infrastructure to a group called Ecma International. Soon after, in 2001, they shared the official C# rules as ECMA-334. By 2003, C# became an official standard through ISO and IEC. Over time, more rules and features were added, like partial classes and special types.

The rules for C# are protected to ensure fair use. Microsoft promised not to use certain patents against open-source projects and some products. Later, Microsoft made free tools for C# that work on many different systems.

Implementations

Microsoft made free tools and compilers for the C# programming language. The first compiler, called Roslyn, changes C# code into a special form called intermediate language (IL). Another compiler, RyuJIT, quickly changes IL into code your computer can use. RyuJIT is free and written in C++. Roslyn is written in C# and helps developers build tools to check and improve code.

There are different versions of C#. One version works only on Windows, while another works on many types of computers. These versions now share a common free version called .NET 5.0. Other projects, like Mono, also provide free C# compilers and tools. Tools like Elements can change C# code to work on many different systems, including games. Popular game engines like Unity and Godot use C# for creating games.

Related articles

This article is a child-friendly adaptation of the Wikipedia article on C Sharp (programming language), available under CC BY-SA 4.0.

Images from Wikimedia Commons. Tap any image to view credits and license.