0% found this document useful (0 votes)
54 views13 pages

Getting Started in C by Hamilton Rice Final - With Track Changes

Uploaded by

api-558905105
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views13 pages

Getting Started in C by Hamilton Rice Final - With Track Changes

Uploaded by

api-558905105
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Getting Started With C#

How to set up a C# development


environment get started coding.

C# is a modern and powerful programming language that can


be used to create web applications, mobile apps, desktop
applications, video games, and much more.

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.

What you need

You are going to need a few things before you get started:

● .NET 2.1 or later

● Visual Studio Code (or an equivalent source code editor)

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.

Once you have a terminal open, type the following command:


dotnet --list-sdks

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.

Mac and Windows:

1. Visit the download page: https://dotnet.microsoft.com/download


2. Make sure your operating system is selected
3. Click “Download .NET SDK x64” or “Download .NET” depending on your operating
system

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:

1. Click “Install .NET”

2. Look for your distribution and version compatibility


3. Follow the instructions for your package manager
4. Verify that the installation was successful by running the command:

dotnet --list-sdks

Installing Visual Studio Code

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:

1. Visit the download page: https://code.visualstudio.com/


2. Select your operating system from the dropdown

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:

Setting up Visual Studio Code

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.

1. Click the Extensions icon on the left

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:

2. Click Open Folder:

This will open your file browser.

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:

5. Select your HelloWorldthis folder


6. If you are greeted with this screen, select Yes, I trust the authors
7. At the top of the window, select Terminal > New Terminal

8. The terminal will open at the bottom of your screen and should have your file path

In this case D:\Projects\HelloWorld


Creating a new project:

Once you have a terminal window that is open at your desired file path, type the following
command:

dotnet new console

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

This command creates three new items in the directory:


● obj
● HelloWorld.csproj (this will vary depending on the folder name)
● Program.cs

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

Your output should look like this:

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:

● Number guessing game (beginner):


○ Generates a random number and the user tries to guess what the number is
○ Input/Output, conditionals, variables, random numbers

● Weather app (intermediate):


○ Make an API call to OpenWeatherMap, parse the data, and display the data to
the user
○ JSON parsing, API calls
● Twitter bot (advanced):
○ Build a bot user on twitter
○ Advanced API calls, project structure

You might also like