C# TUTORIAL

Explaining Hello World Program



Let us take a look at the first four lines of the code.


 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;





"using" is a keyword. A keyword is higlighted in blue in Microdoft IDE editor. The keyword using imports a namespace. A namespace is a collection of classes. We will get into the details of classes later on. For now you can assume the classes as a set of variables, properties and classes. In our program we have imported four namespaces. If you notice, we have our own namespace ConsoleApplication1.

 namespace ConsoleApplication1




Next we define our own class. The C# is an Object Oriented language. every line of code that actually does something, is wrapped inside a class. In the case, the class is called Program.

class Program





A class can contain several variables, properties and methods, concepts we will go deeper into later on. For now, all you need to know is that our current class only contains one method and nothing else. It's declared like this:
 static void Main(string[] args)


We will now explain the above line. The first word static is a keyword. The static keyword tells us that this method should be accesible without creating an instance ofthe class. The next keyword is void, and tells us what this method should return. The void means it returns nothing. For instance, int could be an integer or a string of tex. The next word is Main, is the name of our method. This method is the so-called entry-point of our application, that is, the first piece of code to be executed, and in our example, the only piece to be executed. Now, after the name of a method, a set of arguments can be specified within a set of parentheses. In our example, our method takes only one argument, called args. The type of the argument is a string, or to be more precise, an array of strings. Windows applications can always be called with an optinal set of arguments. These arguments will be passed as text strings to our main method.