01. C# Fundamentals: Hello World

For the sake of simplicity, We’ll be using a free online editor called Repl. This online editor reduces the complexity of local configurations. But if you would prefer to use a local text editor or IDE Visual Studio, or Visual Studio Code are great tools to help you get started. Below you will find the following snippet of code that We’ll digest:

using System;

class MainClass {
  public static void Main (string[] args) {
    Console.WriteLine("Hello World!");
  }
}

When we run this code we’ll receive an output of:

> Hello World! 

Lets digest this a little bit to see what is actually going on under the hood.

using System – This line essentially imports something called a “namespace” into our program to aid in writing code. Don’t worry too much about this, but just keep in mind that there are several Namespaces within the C# language, some refer this to a library or a composition of classes and methods that assists in writing code. Code is very complex and sometimes we want to prevent the theory of “re-inventing the wheel” as much as possible.

class MainClass – classes in C# are known as a “Blueprint” in the physical world, classes can be used for several operations in programming, but for now consider it to be a like the frame to a house. Or to put it into perspective of automobiles, we can define a class called “Automobiles” and derive several automobiles from this class such as Ferrari’s, Lamborghini’s, and Bugatti’s:

public static void Main (string[] args) – This is essentially the main portion of the program, and usually how your program is executed. If we put this in terms of automobiles, this method is essentially like the programmer inserting the keys into the ignition and starting the engine. Whatever is written in this section will be executed.

Console.WriteLine("Hello World!"); – This Line of code utilized the using System; namespace and calls onto the Console which will output what is passed into the parenthesis as arguments, in this case it’s Hello World! .

That’s it for your first C# program! In the next article, we’ll dig a little deeper into this code and manipulate some parts to develop a deeper understanding.