HelloWorld is typically  first application that young programmer writes so we will write one as well.

 

Lets start analysis our code bottoms up.

Console – we use Console class that resides in System namespace to access method WriteLine

WriteLine – is a method which we use to display desired output to our console application

(“Hello World!”) – is an input parameter of Write line method. If you take look at  this link you will see every possible overload type that WriteLine can take. In this specific example we are overloading WriteLine method with string.  Strings will be covered in their own post.

public – public keyword is an access modifier.

static – we will discuss static keyword in latter post.

void – void is a return type. Every method has to have one. Void keyword is used to specify that this method doesn’t return a value. Return types will be covered in later post when we will discuss Methods.

Main() – represents Method that takes no input parameters.

Class is an important subject and will be covered in future post along with namespaces.

Comments can be found all around any code an is used to remind user (programmer) what some line of code/method/class/etc means or how to use it. Comments can be created by putting two upper slashes (//) and will comment only one line of code. Alternative way of creating a comment is by using following syntax:

For now all you need to know is that this line of code is used to access Console class and that using keyword in this context is called using directive and will be covered in future post.

Try running your code. Depending how fast your computer you will briefly see black console (command prompt). Why doesn’t it stay opened? You could run the program with Ctrl+F5 to run it without the debugger attached but that does not solve our problem. Put breakpoint on line “Console.WriteLine(“Hello World!”); ” and run program. Now we can see our console application with HelloWorld message. Jump into your Visual Studio and press F10 key twice. And you will see that our program has continued to curly brackets. What can we do to allow our user to decide freely when our program will stop executing? Well we could add following line beneath “Console.WriteLine(“Hello World!”); “

Run again program and you will see “HelloWorld!” printed inside Console application, and application will exit when we press any key.

Hooray, we wrote our first application using C#!