Hello World

Probably the classic first application almost everyone has written (and still write when they are learning a new environment or programming language), is Hello World.  The point is to simply validate that you have the environment setup properly, and that you understand the basic language syntax and compiler well enough to get something that will RUN.  Remember, that we are using the C# (C-Sharp) programming language for our examples, however you can easily translate these into other programming languages, as the same rules apply across all programming languages, merely the syntax of how those rules are communicated to the compiler are different.  Simply follow these steps to create your first application:

  1. If your Visual Studio development environment isn't already running, please start it.
  2. Click on File > New > Project, or simply click on the 'New Project' toolbar button.
  3. On the left-hand side of the new project dialog, make sure you choose Templates > Visual C# > Windows, and in the primary dialog area, choose Console Application.  Give the project a name of 'HelloWorld' and click OK.

This should create your project, and in your development environment you should see the basic code necessary to have your application run.  Change the code in your Program.cs file to match the following:

using System;

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

Now, click on Debug > Start Debugging, or on the > Start button on the main toolbar.  At this point a black console window should appear with the text 'Hello World' in it - by pressing the Enter key, the window will close.

Congratulations, you have completed your first Windows application!  It's quite simple, and if you are anything like my clones, you will have some fun changing the text to say anything you want, like 'Where are my pants?'.

So what's important here?  Generally, just remember that Methods (e.g. Main) live inside a Class (e.g. Program), Classes live inside Namespaces (e.g. HelloWorld), and braces define what's inside and outside (e.g. { inside } ).  I will put in another post much greater detail regarding what exactly each line does, and why it's important, but that's only for those who want to know.  :)

Until next time!

Download the HelloWorld project & solution used here