top of page

Lesson 1 : Hello World

Write your very first program by following the simple programming tradition of greeting the planet Earth.

Lesson Summary:

Hello World

"Hello World" is a coding tradition where we create a fully-functioning program that simply outputs the text "Hello World". The purpose is to setup a fully-working build of the programming environment with the given language, so that we can start writing some real code. Hello World is not just about writing the code itself; it's also about having all the right components of the language downloaded into your operating system, including things like the IDE (Visual Studio) and the compilers (which are included with Visual Studio for C#). For example, in Python, Hello World is just the follwing code in an otherwise empty file:

     print "Hello World"

However, in order for that to work, you also need to download all the stuff necessary to actually run a Python script. The difficulty of "Hello World" can vary thus vary wildly depending on the language and environment, becoming potentially quite difficult without the proper tools and knowledge. Luckily for us, Visual Studio makes Hello World trivial for C#.

What we did

In this lesson, we simply used Visual Studio's "New Project" templates to create a fully-functioning console application, and added a tiny bit of code to output "Hello World" to the console. A console application is a very simple application that makes use of Window's command prompt to input and output text from and to a console, respectively. It's a great way to start programming simple programs.

For this chapter, don't focus on the significance of the actual code we wrote; the purpose of this lesson is to get your coding environment set up and running. We will start to focus on the code itself in the next lesson, going forward.

Lesson Code:

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

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {

            Console.Out.WriteLine("Hello World");
            Console.In.Read();
        }
    }
}

Lesson FAQ:

What are usings, System, static, string, class, etc.? Why don't you explain what they are now instead of later?

I will cover each and every one of these topics at the right time, as they come along. Explaining these now would not be very helpful, since it would only be confusing and wouldn't really have any benefits. For now, let's focus on core concepts so that when we cover these other concepts, we can understand them more effectively.

For these lessons, simply focus on having your code between the two curly braces, { }, immediately following this line:

             static void Main(string[] args)
 

That is, unless the lesson specifically suggests otherwise!

I am not getting the same results, or something is failing and I get errors and don't know why!

If you have not done so yet, watch the "Common Gotchas" addendum episode directly below this Lesson (on this page). I cover most common errors there.

 

If that does not resolve your issue, try posting your question on the YouTube channel; I (or someone else), may try to answer it. Another thing you could try is to go to Google and type the error you see into Google; you will often see the question posted and responded, unless your error is very esoteric. 

Additional Notes and Tips:

Code Comments

You can put comments in your code by using two forward slashes, //. The entire line following the forward slashes will be ignored by the compiler, meaning it can contain any text you want and it will not break your program. These are formerly referred to as code "comments". For example, note the following code:

    static void Main(string[] args)
    {

      // This is a comment. It will be ignored by the compiler when building the code

      Console.Out.WriteLine("Hello World"); // You can also put comments at the end of a line of code

   }

   // You can put comments anywhere on your code file. Visual Studio will color them green

I will often use comments to make notes about code samples, so keep an eye out for this.

Addendum: Common Gotchas

Addendum

I will help you demystify pesky errors by enumerating some common issues that beginners face.

bottom of page