In this tutorial I will show you how to: download and install the .NET SDK, create a C# project, run your C# project, and edit your code.

Download and install the .NET SDK

In order to write software applications using C# you’ll need to have the .NET SDK installed.

You’ll need to download the .NET SDK and choose the latest LTS (Long Term Support) version for your operating system. Once the installation package has finished downloading, run it to install the .NET SDK.

Once everything is installed, open a new terminal window and run this command:

dotnet 

If you see an error saying ‘dotnet’ is not recognized as an internal or external command then something went wrong. Try restarting your computer and following these steps again. If you didn’t see any errors, you should be ready to go!

Create your project

Open a new terminal window. In your terminal window, run these commands to create your project:

dotnet new console -o HelloWorld

The dotnet new console command creates a new console project for you.

The -o parameter creates a directory called HelloWorld where your project is stored and populates it with the required files.

Now, navigate to the new directory created using the previous command:

cd HelloWorld

The cd HelloWorld command changes your current directory to the one just created for the new project.

Run your code

In your terminal window, run this command:

dotnet run

You should see this output:

Hello, World!

That’s it. You just built and ran your first C# application.

If you’re curious about what happened behind the scenes: the dotnet run command compiled your C# code into an executable and ran it. You didn’t need to set up a build tool or configure anything. The .NET SDK handled all of that.

Edit your code

Now let’s change what the program does. Open the file called Program.cs in any text editor (VS Code, Notepad, or whatever you have handy). You should see something like this:

// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");

If you’re used to seeing a Main method and a namespace in C#, you might be surprised. Newer versions of .NET use what’s called top-level statements, which means you can write your code directly without the ceremony of a class and method wrapper. The compiler adds that structure for you behind the scenes.

Change the text inside the quotes to whatever you like:

Console.WriteLine("Hello from my first C# app!");

Save the file, go back to your terminal, and run dotnet run again:

Hello from my first C# app!

You just edited and re-ran your program. Console.WriteLine is the method that prints text to the terminal. You’ll use it constantly when you’re getting started.

What’s next?

From here you have a working development environment and a project you can experiment with. A few things worth trying:

  • Add more Console.WriteLine lines and run the program again to see multiple lines of output.
  • Try Console.ReadLine() to accept input from the user.
  • Explore the official C# tutorials on Microsoft Learn for a deeper introduction to the language.

The hardest part of learning to code is getting that first project running. You’ve already done that.

Leave a Reply

I’m Peter

I’ve spent my career building software and leading engineering teams. I started as a developer and architect, grew into engineering leadership, and today I serve as a Chief Technology Officer.

Here, I share practical insights on technology, leadership, and building high-performing teams.

Connect with me on LinkedIn.

Discover more from Peter Mourfield

Subscribe now to keep reading and get access to the full archive.

Continue reading