Introduction

C# is pronounced "C-Sharp".

C# has roots from the C family, and the language is close to other popular languages like C++ and Java.

The first version was released in year 2002. The latest version, C# 12, was released in November 2023.

C# is used for:
  • Mobile applications
  • Desktop applications
  • Web applications
  • Web services
  • Web sites
  • Games
  • VR
  • Database applications
  • And much, much more!
Why Use C#?
  • It is one of the most popular programming language in the world
  • It is easy to learn and simple to use
  • It has a huge community support
  • C# is an object oriented language which gives a clear structure to programs and allows code to be reused, lowering development costs
  • As C# is close to C, C++ and Java, it makes it easy for programmers to switch to C# or vice versa
C# IDE

The easiest way to get started with C#, is to use an IDE.

An IDE (Integrated Development Environment) is used to edit and compile code.

In our tutorial, we will use Visual Studio Community, which is free to download from visualstudio.microsoft.com

Applications written in C# use the .NET Framework, so it makes sense to use Visual Studio, as the program, the framework, and the language, are all created by Microsoft.

Install

Once the Visual Studio Installer is downloaded and installed, choose the .NET workload and click on the Modify/Install button:

After the installation is complete, click on the Launch button to get started with Visual Studio.

On the start window, choose Create a new project:

Then click on the "Install more tools and features" button:

Choose "Console App (.NET Core)" from the list and click on the Next button:

Enter a name for your project, and click on the Create button:

Visual Studio will automatically generate some code for your project:

That's it, you may now explore C#

Output

To output values or print text in C#, you can use the WriteLine() method:

Console.WriteLine("Hello World!");

You can add as many WriteLine() methods as you want. Note that it will add a new line for each method:

Console.WriteLine("Hello World!"); Console.WriteLine("I am Learning C#"); Console.WriteLine("It is awesome!");

You can also output numbers, and perform mathematical calculations:

Console.WriteLine(3 + 3);

There is also a Write() method, which is similar to WriteLine().

The only difference is that it does not insert a new line at the end of the output:

Console.Write("Hello World! "); Console.Write("I will print on the same line.");

Note that we add an extra space when needed (after "Hello World!" in the example above), for better readability.

Console.Write("Hello World! ");