C# Tutorial – Part 1: Getting started

As mentioned in the portfolio post, I will publish a series of coding tutorials about the MyQA project. How did I study C# – one of the popular programming languages for game development – and Gtk# – one of the GUI tools – for my project? How did I do the project (version 1) step by step? Importantly, this series of coding tutorials are from very basic to little advanced level, so the first few tutorials may be quite easy for those who have already known a basic programming concept.

In this first tutorial, you will learn more about 2 things:

  1. Which IDE did I use for my project? How to use it?
  2. A few basic syntaxes in C# programming language.

Which IDE did I use for the project? How to use it?

IDE stands for Integrated Development Environment. It is a basic tool required to write and test software. With the support of IDE, you will save lots of time on writing or debugging your program if you are a newbie in programming.

Visual Studio - IDE for C#

I used Visual Studio – Community version – for the MyQA project. Visual Studio is one of the most famous tools for C# programming language in game development. In order to download this IDE, you can visit this website. It supports on either Windows or macOS. However, the user interface is quite different between both. In this series of coding tutorials, I will use the one on macOS.

Create a new project with Visual Studio

Create a new project with Visual Studio

After installing Visual Studio – Community version – in your local machine, you will have this on your screen so that you can open an existing project or create a new project. Since this tutorial is the first tutorial, I choose ‘create a new project’ for the ‘Hello World’ console app.

Create a 'Hello World' console app with Visual Studio

Create a ‘Hello World’ console app with Visual Studio

After clicking on the ‘create a new project’ button, you will have this on your screen. Because there is the ‘Hello World’ console app in this tutorial, you need to make sure that you choose .NET Core – App – Console Application.

Configure a 'Hello World' console app with Visual Studio

Configure a ‘Hello World’ console app with Visual Studio

After clicking on the ‘Next’ button, you will need to type the name for your program. The solution name of your program will be similar to the project name by default. In this tutorial, I name my project to be ‘FirstApp’. To be more practical, the name of your project should be capitalized the first letter of each word and there is no space between each word.

The first sight of a 'Hello World' console app

The first sight of a ‘Hello World’ console app

After creating the new console project, you will have this on your screen. There are a few things you need to know.

  • The solution explorer on the left side of your screen helps you easy to find the file you are working on or to switch to another file when you do coding.
  • The name of the file is automatically similar to the class name after you create a new file. Therefore, it should be capitalized the first letter of each word and have no space between each word. This helps your project more practical.
  • The namespace is similar to the project name. The namespace is nothing but the place where all classes in one project are able to communicate with each other. To this point, you may raise the question “What if we want to use a specific class of another project?”. This topic will be covered later in this series of coding tutorials. Therefore, I leave it there so that you can google it.
  • On top of the program, there is always the “using” statement which is used to import the built-in library or even the customized library from your project.
  • The Main block is where your program is operated. It should have at most 1 per project in order to run your program.

A few basic syntaxes in C# programming language

A 'Hello World' console app with Visual Studio

A ‘Hello World’ console app with Visual Studio

This is the complete ‘Hello World’ program which I made for this tutorial. This program covers a few necessary basic syntaxes in C# programming language.

  • Line 10-11: This is how you declare/assign/initialize the local variables/elements for your program. The syntax for this is [data type] [variable name] = [value]/[empty object]/[operator].
  • Line 12: This is the way how you initialize the local variables with the use of operator/equation/formula.
  • Line 13: This is the way how you create an array with the new keyword. The array is nothing but it is like a bag and used to store many variables/elements with the same data type. Since C# is an object-oriented programming language, everything in your program will be treated as an object. Therefore, the new keyword is used to create a new object. the syntax for this is[object type] [object name] = [new] [object type](). Let’s imagine that you are a new player in your program and your program treats you as an object. So, it will be Player p = new Player(). To this point, you may raise the question “How did the program know what your name is?”. Again, we will discuss this topic later in this series of coding tutorials. Therefore, if you want to learn more, I encourage you to google it first or you can wait for my upcoming tutorials.
  • Line 16-20: This is the way how you help your program make a decision with the if-else statement. If the condition is true/correct, the program will execute/run the block of code inside the if statement. Otherwise, it will execute/run the block of code inside the else statement. For example, in this program, c = 20, so the condition of the if statement is false/not correct and hence the program will print "The sum of a and b is less than or equal to 20". The Console.WriteLine()is the built-in method which is in the System library – look at line 1.
  • Line 22-25: This is the first type of the for loop statement. The for loop statement is used to repeat the action/the list of actions based on the required times. In this code, I ask the loop to repeat 10 times because the initialized array is able to have at most 10 elements inside it. Importantly, line 24 is the way how you assign/add the element into the array. The syntax is [array name][index] = [value]. In addition, this first type of loop is called iterative loop, which you are able to control the number of repeated time by initializing the starting point and the ending point.
  • Line 27-30: This is the second type of the for loop statement. Let’s say you don’t know how many elements the array contains but you want to print all elements inside it. This is when you should think of the second type of the for loop statement. It will run linearly through each object/element in the array and print that object/element until there is no element after the last element. The syntax is foreach ([object type] [object name] in [array]) { do somthing }. In addition, this second type of loop is called object iteration, which you loop through each object without the need of knowing the starting point and the ending point.
The output of a 'Hello World' console app

The output of a ‘Hello World’ console app

This is the output of the program in this tutorial. To run the project in Visual Studio, you can either click on the ‘Play’ button on the top left or press F5.

These are just a few necessary basic syntaxes in C# programming language. To learn more, you can visit this website. Other syntaxes will be covered when I start the tutorial about the MyQA project. However, it is better if you know them before my upcoming tutorial posts.


That’s it for this tutorial. Hopefully, it helps you make more sense about programming in C# language now. Please let me know what you want to learn next and I will consider to put it in my upcoming tutorials.

If the image in this post is unclear, I have uploaded them to my Github repository. You can visit this link to have clearer images.

Thank you for reading.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s