Header Ads

C# Tutorial - 1. Create C# application with Visual Studio

how to create visual c# application

Welcome to the very first lesson of my Visual C# Tutorial. In this tutorial, we are going to learn how to build the most simple C# application called "Hello World". It is simply going to show the message "Hello World" in the console window which is also known as "CMD". The objective of this lesson is to learn about how to create new project and write some codes. For now, please do not worry if some codes or rules don't make sense to you. I am going to explain every single line of codes that we write throughout this lesson.

Step 1. Create new project                                                                        

We are going to launch new program. In visual studio's file menu, I am going to select new project.

Now you would have the new project dialog. There, you can click Visual C# templates on the side pane and choose the console application in that center pane. I want you to double-check that you chose the Visual C# template since some would choose wrong template.

how to create visual c# application










Tip. console application simply refers to the program that works at a command line console in relation to C#. It will accept input and show output at the console.  
Then after a moment or so, you are going to be loaded into the main pane of the IDE which stands for "Integrated Development Environment". This pane is actually based on the template that you chose.

how to create visual c# application


 As you can see, there are two curly braces right underneath static void Main(string[] args) method. Those two braces are basically identifier for the start and end of your program. So you should put your codes between those braces for your program. We are going to break what the static method does with this program later on other tutorials. So for now, let's just keep moving forward.

how to create visual c# application



Step 2. Write codes for method displaying the message                          

Let's make some spaces between those two braces of static void Main(string[] args) method so that your code can be a bit more noticeable. Then, you can type these following codes for your displaying method.

Console.WriteLine("Hello World");
how to create visual c# application
Notice the capitalization of "C" for Console keyword and "W" and "L" for WriteLine. Then, I have got two double quotes between the message "Hello World" surrounded by parentheses. It basically tells the visual studio that Hello World is string value. Anyway you should always put double quotes for string values in C# programming. Don't forget to put semi-colon at the end of your code. It is very important identifier for telling visual studio that this code ends here!.

Tip. As you can see, there is no space between those two words, Write and Line. Instead, I put uppercase for the first letter of the second word "Line" to put them together. It is called "Camelcase". When you have two words as you write a program, you would use this naming convention.
 Then, I will do the same with different method called "ReadLine". As you can see, ReadLine is camel cased as well. You can just put it right underneath the first method WriteLine. Even if you don't have any string value in between those two parentheses, you should have them. We are going to learn about them in detail later.

Console.ReadLine();
how to create visual c# application
Let's just make sure that you have got the exact same code as mine before we run this code. Accuracy really matters when it comes to programming code since it is read by computer which is a.k.a Stupid Box.

Tip. if you have red line right under your code, it is basically telling you that you typed something wrong just like MS Word. So take a careful look at your code when you run into this line. 

Step 3. Run the code                                                                               

Once you have double checked your code, let's try to run your code and see if it works correctly or not. First of all, click the "save all" button in the toolbar at the top menu. It visualizes with overlaying two disks.

how to create visual c# application
 Then, click the "Start" button to run your code.

how to create visual c# application
Now, you would have this console window with the message "Hello World".

how to create visual c# application






If you have this window, you did everything correctly. Now you are successful at running your very first application with Visual C#.

No comments

Powered by Blogger.