C# basics: what the language is and where it is used

What C# is

C# (pronounced C sharp) is an object-oriented programming language with static typing. A group of Microsoft engineers led by Anders Hejlsberg and Scott Wiltamuth designed it in 1998-2001 as the language of the .NET platform; ECMA-334 and ISO/IEC 23270 standardise it.

The syntax belongs to the C family and is closest to C++ and Java. On top of that base the language has properties, events, delegates, attributes, generics, iterators, anonymous functions with closures, LINQ, exceptions and async methods.

A C# program is compiled to an intermediate language, and the runtime compiles and runs that on the target machine, with a garbage collector that reclaims memory. The compiler stops on a type error before the program ever starts, which is the practical difference from a dynamic language.

Where C# runs

.NET runs on Linux, Windows and macOS, so one project builds for a server, a desktop and a container. The usual targets are web services and APIs with ASP.NET Core, desktop windows with WPF or WinUI, mobile applications with .NET MAUI, games with Unity and command-line tools.

A project is a folder with a .csproj file that lists the target framework and the packages. The same SDK builds it on every system, and dotnet publish produces either a self-contained binary or a small file that needs the shared runtime.

Install the SDK

Install the .NET SDK, not only the runtime: the SDK brings the compiler and the dotnet command. The installer is on dotnet.microsoft.com, and it also adds the Microsoft package feed to the system. Once that feed is in place, one command installs a release:

sudo apt install -y dotnet-sdk-10.0

Check what is installed before you write code:

dotnet --version

10.0.100

A new .NET release arrives every November, and every second one is a long-term support release. A newer SDK prints its own number.

Hello, C#

The SDK creates a working project with one command, and the project directory holds a single source file:

dotnet new console -o hello

cd hello

Open Program.cs and replace the generated line:

Console.WriteLine("Hello, C#");

The template writes that line without a class and a method: top-level statements save the ceremony for the first program. Build and run it:

dotnet run

Hello, C#

The same program in the classic form, which every older example uses, names the entry point explicitly:

class Program { static void Main(string[] args) { Console.WriteLine("Hello, C#"); } }

Where to go next

The compiler reports a type error with the file, the line and the member it could not resolve; read the first diagnostic before the rest. After the first program the next step is the type of a value: how to find out the type of a C# variable.

For a language with the same C-like syntax and a different runtime, see Java; for the editor of this page, see Visual Studio.

Version numbers move with every release: a newer SDK prints its own, and the Hello, C# line is the same on all of them.

Article author: Arthur Isaev