ZetCode

C# tutorial

last modified January 22, 2024

This is C# tutorial. In this tutorial you will learn the basics of the C# language.

The basics of C# are covered in C# basics, C# lexical structure, C# variable, C# statement, C# flow control, C# operator, C# data type.

Object-oriented programming is covered in C# class, C# object, and C# OOP.

C#

C# is a modern, high-level, general-purpose, object-oriented programming language. It is the principal language of the .NET. It supports functional, procedural, generic, object-oriented, and component-oriented programming disciplines.

The design goals of the language were software robustness, durability and programmer productivity. It can be used to create console applications, GUI applications, web applications, both on PCs and embedded systems. C# was created by Microsoft corporation.

.NET

.NET is an open-source, general-purpose development platform maintained by Microsoft and the .NET community on GitHub. With .NET, we can use multiple languages, editors, and libraries to build for web, mobile, desktop, games, and IoT.

$  dotnet --version
8.0.101

In order to work with .NET, we need to dowload and install .NET SDK. The .NET 8 supports C# 12.0.

Compiling C# programs

After installing .NET SDK, we can build our first C# program.

$ dotnet new console -o Simple

With the dotnet new console command, we create a new console application.

Program.cs
Console.WriteLine("This is C#");

This is a simple C# program that prints a message to the console.

$ dotnet run
This is C#

We compile and run a simple C# program with dotnet run.

Visual Studio Code

Visual Studio Code is a lightweight, powerful, modern source code editor which is available for Windows, macOS and Linux. It comes with built-in support for JavaScript, TypeScript and Node.js and has a rich ecosystem of extensions for other languages and runtimes including C# and .NET.

It includes support for debugging, embedded Git control, syntax highlighting, intelligent code completion, snippets, and code refactoring.

Source

C# language reference

List all C# tutorials.

Author

My name is Jan Bodnar and I am a passionate programmer with many years of programming experience. I have been writing programming articles since 2007. So far, I have written over 1400 articles and 8 e-books. I have over eight years of experience in teaching programming.