Beginning C# – Boring Hello World

Programming is about making the computer do what you want. Many programming languages exist, and I’ll concentrate on showing how you can learn C#, one of the easier languages in my opinion.

First, go to the Microsoft Visual Studio C# Express site, and download the free software compiler. A compiler is simply a software that turns your code to a program. The download link should look like this:
Visual Studio C# 2005 Express download

So you install the software and create your first C# project, and name it “ConsoleHelloWorld”. All you need is to add this line of code

Console.WriteLine("Hello World!");

and you’ll have the famous “Hello World” program!

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

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

Compile and run the program in Visual Studio by using Ctrl + F5, or using the menu options [Debug] -> [Start Without Debugging].

The Hello World program is the simplest piece of code with a complete program structure. It is also one of the most boring pieces of code in existence because it does practically next to nothing. That said, the program structure is complete, so we’ll dissect that.

The using statements
These can be thought of as shortcuts for writing code. The following two lines of code are basically the same, thanks to the using System; statement.

Console.WriteLine("Hello World!");
System.Console.WriteLine("Hello World!");

The namespace keyword
It’s just a fence, making sure the code stays in a specific scope. And the meaning of “in scope” is … too much for you to handle at this point.

The class keyword
The “class Program” line of code just means that “Program” is a class, where “Program” is the name of your, uh, class. A class is a chunk of code containing instructions. … And is also too much for you to handle at this point.

The Main thing is …
Where all the action is taking place. It can take other forms besides

static void Main(string[] args)

but I’ll have to explain its other incarnations some other time.

So what can I tell you? Part of your programming experience is to simply ignore what you don’t know and write what code you do know. In our example, you just need to add one line of code. That’s it. Which reminds me. I haven’t explained what that line of code did.

Console is a class, and it has a function called “WriteLine”. If you feed the string “Hello World!” to the function WriteLine, it will be displayed. It’s called a “string” because it’s just a string or a series of characters.

I feel like I’m treating you like a fool, so instead of insulting your intelligence further, I suggest you pick up any C# beginner programmer book. I can almost guarantee the first chapter is on how to write a Hello World program.

And if you don’t get anything yet, then remember that part of being a fantastic programmer is the skill of selective ignorance.

Download source code

Comments are closed.