A profile picture of the author

Learning C# - Workshop One

A photograph of a misty road with a shadowed trees overhead


In this workshop, we will create a basic application called a console application. This is an app that runs on the terminal, sometimes known as the console or command line. On a Windows machine, we can use the cmd or Powershell as our console. On Linux, it’s the terminal. And on macOS, it’s also terminal or you can download iTerm and use that instead.

We will also be using the command line to create and run our application.

Setting up our development environment.

To get started with C# we will need to download a Software Development Kit, or SDK. C# runs on a framework called .NET (dot net) and we will download the .NET SDK here. Choose the correct download for your operating system, e.g. Windows, and follow the installation instructions.

We will also need a code editor to enable us to edit our code. Visual Studio Code is a free and very versatile editor, so let’s download that one, again, choosing the right download for your operating system.

To check if the .NET SDK installed correctly, open the terminal and type in dotnet and press enter. You should see something similar to this image showing dotnet in the console Now that we know the SDK is installed correctly we can make our first application. When you open the terminal it will most likely open in a certain folder or directory on your computer. If you type in ls and press enter, you should see a list of all the folders and files in the current directory. It may look something like this: image showing contents of new console app We need to create a new directory for our code to live in. To make a new directory we will use the following command:

>mkdir Repos

If you type in ls again, you should see we now have a new directory called Repos. We now need to change directory (cd) so that our terminal is inside our new folder.

>cd Repos
>dotnet new

image showing dotnet new in the console The above command will bring up all the available templates projects that came with the SDK. We want to build a console app, so enter the following command:

>dotnet new console -n HelloWorld

This command will create a new Directory called HelloWorld and add a new console application inside it. If cd into the HelloWorld directory and list all the files we will see with have 2 files called Program.cs and HelloWorld.csproj. image showing contents of new console app We now have a basic application that we can run. Type in the following command:

>dotnet run

We have made our first program! Let’s go edit our program!