Start Debugging
2023-06-11 csharpdotnet

How to start programming with C#

A beginner's guide to getting started with C# programming, from setting up Visual Studio to writing your first program and finding learning resources.

C# is a modern, general-purpose, object-oriented programming language developed by Microsoft. It is widely used for Windows desktop applications, games (especially using the Unity engine), and web development through the ASP.NET framework.

C# is considered to be beginner-friendly and is a great language for new programmers. Below we explore some of the reasons why C# is considered beginner-friendly:

Getting started

The first thing to do is to set up your environment. You can use any operating system to write C# and there are multiple choices when it comes to editors as well. You can even write and run C# code in the browser on your phone or tablet using websites like .NET Fiddle.

A typical developer environment would be Visual Studio running on Windows. Visual Studio comes with a free Community edition which you can download from here. Once you’ve downloaded the installer, proceed through the install wizard with the default workloads, and once it’s finished, you should have everything ready to write your very first C# program.

Writing your first line of C# code

C# code files are written and compiled part of a project. Multiple projects make up a solution. In order to get started, we’ll need to create a New Project first. You can use the Quick actions in the Welcome page to create a new C# project.

Quick actions in Visual Studio 2022, with New Project highlighted.

To start simple, we’ll want to create a new console application. Search in the list of templates for ‘console’ and choose the one which has the C# badge as indicated below:

A list of project templates in Visual Studio 2022, with the C# console application template highlighted.

Continue through the wizard using the default values and you should end up in a state similar to this:

Visual Studio 2022 showing a new C# console application using top-level statements.

On the right, you have your Solution Explorer, which shows your solution, your project, and your code file: Program.cs. The file extension: .cs – stands for CSharp (C#). All your C# code files will have the same extension.

In the center of your editor you have this Program.cs file open. The file contains two lines of code.

Next, let’s run the program and see what it outputs. To compile and run the program, you can use the Run button in the toolbar, or simply press F5.

A toolbar in Visual Studio 2022, having the Run button highlighted.

Visual Studio will first compile your project and then execute it. This being a console application, a console window will show up, with the message “Hello, World!” on the first line.

A console window displaying “Hello, World!”.

Learning resources

Now that your environment is properly set up and you’ve run your first C# program, it’s time to start learning more about the language. To that end, there are several great resources available to get you started. We’ll enumerate a few below:

< Back