Explaining Hello World

using System;

namespace HelloWorld {
    class Program {
        static void Main(string[] args) {
            Console.WriteLine("Hello World");

So let's walk through the semantics of what the code above tells the compiler, and more importantly the Operating System, to do:

using System:  This tells the compiler that the code below will reference the named assembly or library.  This allows you to use code previously written either by yourself, or someone else.  There is an entire framework of assemblies with solid code for you to build on - at the time of this writing, you can find the documentation here.

namespace HelloWorld:  Namespaces are ways to organize your code, and control name conflicts.  As your own code library grows, you will want to organize it in logical ways so it's easy to find, such as '<Your Name>.Net', '<Your Name>.Core', which refers to the type of software that lives in each area.  This will make it easier to find your re-usable code later.

class Program:  Classes organize attributes and behavior.  You can think of classes generally as actors or nouns, although that's not always the case.  However, in many cases you will be organizing your code based upon that assumption, such as Person, Location, Car, etc. so that actions and attributes of each type of object are easily found.  You can then create instances of these classes to represent an actual thing, such as "John - a Person, who has brown hair and blue eyes".  We will get further into this later. 

static void Main:  This is a method of the Program class that acts as the entry point for our application that the Operating System will use.  This can take a series of arguments, but generally speaking, when you double-click on an application to run it, this is what gets called first by the Operating System.

Console.WriteLine:  Tells the Operating System to write out the content to the console window.

Console.ReadLine:  Tells the Operating System to wait for someone at the keyboard (a user) to enter in content.  With ReadLine, the application will wait until someone presses the Enter key.

Lastly, you will notice plenty of open { and close } braces.  These instruct the compiler as to the scope of the namespace, class, or method.  Parenthesis (e.g. Main(string[] args) on a method define what is passed from outside of the method into the scope of the method.  Generally speaking:

  • Classes MUST be contained within the scope of a Namespace
  • Methods MUST be contained within the scope of a Class
  • Parameters MUST be contained within the scope of the Method parenthesis

We will also deal later with Class Fields, Class Properties, and Method Fields, but let's not get too far ahead.  Although HelloWorld is a simple example, understanding the basic rules of how to construct Namespaces and Classes will help you to create extremely complex applications without losing your mind.  These concepts are not so important now, but certainly will be later.