Writing a basic hello world program in C#.


m3rcer

This is a basic program printing hello world and the time using core built-in classes.

  • The System namespace allows us to access libraries in a program.
  • Namespaces declare where our classes live in.
  • DateTime is a core C# class for dealing with dates.
  • Compile the source code on linux using the Mono compiler (mcs).

Code:

using System;

namespace hello_world
{
        class MainClass
        {
                public static void Main(string[] args)
                {
                        string hello = "Hello World!"; //simple string definition
                        DateTime now = DateTime.Now; //Build In core class usage
                        Console.Write(hello); //Single line w no newline at end
                        Console.WriteLine("The date is " + now.ToLongDateString()); //Adds newline to the end
                }
        }
}

Output:

Image