Beginner C#: Getting Started
Tags: beginners, tutorial, csharp, dotnet
Published: 2020-09-26 09:43:06

---
title: Beginner C#: Getting Started
published: true
description: Now that I've convinced you, now it's time to start learning. In this article, you will learn how to install Visual Studio and write your first C# program.
tags: beginner,tutorial,csharp,dotnet
cover_image: https://cdn.hashnode.com/res/hashnode/image/upload/v1601113086712/kIpoCYHuj.jpeg
canonical_url: https://samwalpole.com/beginner-csharp-getting-started
---

Now that I've convinced you  [why you should learn C#](https://samwalpole.com/beginner-csharp-why-learn-csharp), now it's time to start learning. In this article, you will learn how to install Visual Studio and write your first C# program.

## What is Visual Studio?
Visual Studio is an integrated development environment (IDE), meaning that it contains all of the tools you need to write, build, run and debug your code. It is primarily build for .NET applications, so it is the recommended IDE for C# developers. It has lots of other cool features too, which you kind [find on the official website](https://docs.microsoft.com/en-us/visualstudio/get-started/visual-studio-ide?view=vs-2019). Furthermore, the Community Edition of Visual Studio is completely free, and that's what we'll be using in this series.

## Installing Visual Studio
First, you need to get the Visual Studio installer. Head over to the [Visual Studio download page](https://visualstudio.microsoft.com/downloads/) and download the Community Edition. At time of writing, the most recent version is Visual Studio 2019.

Once that has downloaded, run the installer and follow the instructions on the screen. At some point you will come to a screen that gives you the option to select certain workloads.

![Visual Studio Workloads](https://cdn.hashnode.com/res/hashnode/image/upload/v1601108767401/LHExv8EH5.png)

Selecting a workload will install all of the relevant tools and software development kits (SDKs) necessary for that particular workload. For now, I would recommend just selecting the 'ASP.NET and web development' workload, although you may wish to select more depending on your interests.

You may also wish to click on the Language packs tab. If your native language is not English, this will allow you to select your own language that will be used inside Visual Studio.

![Visual Studio Language Packs](https://cdn.hashnode.com/res/hashnode/image/upload/v1601109037663/5Hy68_5L-.png)

Once you're ready, click install and wait for it to complete. You're now ready to start developing in Visual Studio!

## Your First Program: Hello World
When you open Visual Studio, you will be prompted with a number of options. First select 'Create a new project'. N.B. I have a dark theme installed on my version of Visual Studio so yours will be a different colour.

![Create a new project](https://cdn.hashnode.com/res/hashnode/image/upload/v1601109501560/aeYFlDYSb.png)

You will then be prompted to choose a project template. For this example, you will want to choose Console App (.NET Core).

![Select project template](https://cdn.hashnode.com/res/hashnode/image/upload/v1601109655054/zkjoQDEru.png)

You will then be asked to choose a name for the project and a location. Once you've done that, click Create.

![Project name and location](https://cdn.hashnode.com/res/hashnode/image/upload/v1601109842943/mMIh2mmy6.png)

You should now see a screen that looks something like this:

![Project screen](https://cdn.hashnode.com/res/hashnode/image/upload/v1601110075889/l7ghZquDB.png)

On the right you will see that we have a Solution called HelloWorld, containing a project called HelloWorld, containing a single C# file (Program.cs).

If you're wondering what a Solution is by the way, it's basically a way to group multiple projects together. At the moment, we only have one project, but as an application grows more complex, it is common to split it in to multiple projects to make it easier to deal with. All of these projects will come under the same solution.

At the heart of every C# program, there is a `Program` class with a `Main` method. This is the entry point of the application and the code that will be run when the application starts. You will see that the template has already added a line of code to the `Main` method. Let's run the application to see what it does. To do this, click on the 'Play' button at the top of the screen, or go to Debug -> Start Debugging.

![Hello World console](https://cdn.hashnode.com/res/hashnode/image/upload/v1601111443374/lEHX_NecT.png)

You should see `Hello World!` printed to the console. This is because the `Console.WriteLine` method takes a string a prints it to the console. A string is a data type in C# that allows you to store text data. In C#, strings are surrounded by quotation marks ("). Try replacing `"Hello World!"` with a different string.

Now that we've made and run our first program, let's try to make it a bit more interactive. We're going to modify the code so that it asks for our name and will then greet us by our name. Here is the new code:
```
using System;

namespace HelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("What is your name?");

            string name = Console.ReadLine();

            Console.WriteLine("Hello " + name + "!");
        }
    }
}
```

The first line prints the sentence "What is your name?" to the console. In the second line, `Console.ReadLine` waits for the user to type something in to the console and press enter. Whatever they wrote gets saved to the variable called `name`, which is a string.

In C#, an every other programming language, variables are a way to store data in your program to be used at a later time. We can the recall the value of the variable by using it's name in code. Variables can store different types of data, but in this case we we are storing the string that comes from whatever the user typed in. [You will learn more about variables later in this series.](https://samwalpole.com/beginner-csharp-variables-and-basic-data-types)

The third line looks a little more complex. Here we are doing something known as string concatenation. Basically it means that we are adding each of these strings together to make one longer string. Try running the program and you will see what I mean.

![Hello name](https://cdn.hashnode.com/res/hashnode/image/upload/v1601112553812/xaOmCVPvp.png)

Here I have typed my name, Sam, into the console. This means that the `name` variable now contains the string `"Sam"`. That means the string concatenation is actually doing `"Hello " + "Sam" + "!"`, which results in the string `"Hello Sam!"` being printed to the console.

## Conclusion
Congratulations! You have now installed the Visual Studio IDE and written your first program in C#. You have learnt the two main console commands that you will come across, and have had a small introduction into variables and data types. Later in this series we will discuss those again in greater detail.

To make sure that you don't miss any posts in this series, please follow this blog and [subscribe to my newsletter](https://samwalpole.com). If you found this post helpful, please like it and share it. You can also find me on [Twitter](https://twitter.com/dr_sam_walpole). If you want, you can also  [buy me a coffee](https://ko-fi.com/samwalpole) ! 😊

---
This post is part of a beginner C# series. I will update this section with links to each post when each new post is published.

1. [Why learn C#?](https://samwalpole.com/beginner-csharp-why-learn-csharp) 
2. [Getting Started](https://samwalpole.com/beginner-csharp-getting-started) 
3. [Variables and Basic Data Types](https://samwalpole.com/beginner-csharp-variables-and-basic-data-types) 
4. [Working with Strings](https://samwalpole.com/beginner-csharp-working-with-strings)