Getting Started in C by Hamilton Rice Final - With Track Changes
Getting Started in C by Hamilton Rice Final - With Track Changes
This guide will help you get started with writing your own programs using C# and .NET. This
guide is aimed at beginners who are hoping to learn but do not know how to get started. You
should be comfortable with installing software onto your computer but you do not need to be
familiar with programming or software development.
You are going to need a few things before you get started:
Installing .NET
.NET is what lets you run your C# code. Without .NET, the code that you write is just text that
the computer has no way of understanding. .NET contains what is called the compiler which
takes the C# code that you write and turns it into instructions that your computer can execute.
Think of the compiler as a translator that helps you communicate with the computer without
having to write out all the instructions as 1s and 0s.
Before installing .NET, make sure that it is not already installed on your computer. Open a
command prompt:
Windows:
1. Open the start menu
2. Type powershell
3. Hit enter, or click on the Powershell icon
Mac:
1. Click the magnifying glass at the top of your screen
2. Type terminal
3. Double click on the terminal icon
The command prompt is just another way to interact with your computer by using text
commands instead of using a Graphical User Interface.
If .NET is installed, your output will look something like this and you can skip the rest of this
section:
This command lists all of the versions of the .NET SDK you have installed on your computer. In
this example 2.1 and 5.0 are both installed.
If you get an error message, that means .NET is not installed and you have to install it to
proceed.
4. Run the installer after it finishes downloading and follow the instructions in the installer
5. Run the command again to make sure .NET has installed properly
dotnet --list-sdks
Linux:
dotnet --list-sdks
The code that you are writing is just text and, as such, you can use any text editor that you want
to write code. Just because you can, does not mean you should. Developers prefer to use a
source code editor which is a special text editor that is designed to edit code specifically. Visual
Studio Code is one of the most popular source code editors, so this guide will show you how to
install and use Visual Studio Code, but any source code editor will work.
If you already have a source code editor installed, you can skip this section.
Downloading the installer:
3. Run the installer after it finishes downloading and follow the instructions in the installer
4. Run the application, it should look something like this:
By default, Visual Studio Code does not come with support for C#, so in order to get the editor
to work properly with C# code, you need to install an extension.
2. Search for C#
3. Select the first extension, developed by Microsoft
4. Click Install
Once the extension finishes installing, Visual Studio Code will recognise and properly function
with your C# code.
Hello World!
You are now ready to get started programming your first project.
You need to open a terminal window at the file path where you would like to create your project.
There are many ways to do this, Visual Studio Code has the ability to do this for you using a
graphical user interface:
1. Click the Explorer icon on the far left:
3. Navigate to where you want to save your project. It is recommended to make a folder
where you store all of your projects, this way you can find them easier. This folder can
be named anything, such as Projects.
4. Create a new folder called HelloWorld, this is where you are going to save your new
project:
8. The terminal will open at the bottom of your screen and should have your file path
Once you have a terminal window that is open at your desired file path, type the following
command:
This command tells .NET to make a new C# Console project. Here is the full documentation for
the dotnet new command, including different project types that can be created with the
command: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-new
The only file that you care about right now is Program.cs. The .cs file extension tells the
computer that this file is a C# source code file.
Open Program.cs:
Take a second to look at this file and try to figure out what it is supposed to do. Once you think
you know what it does, type run the program by typing this command into the terminal:
dotnet run
Hello World is a very common first program when learning a new language. .NET has gone
ahead and done all of the programming for you in this case.
Learning More
You now have a programming environment and can create new C# projects.
If you are learning programming for the first time, check out this collection of tutorials from
Microsoft: https://docs.microsoft.com/en-us/dotnet/csharp/tour-of-csharp/tutorials/
If you are more familiar with writing code and reading documentation, here is the C# language
reference from Microsoft: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/
The best way to learn a new programming language is to write code. Here are some
recommendations for starter projects:
Some recommendations: