Syntax

This is how we print "Hello World!" in C#

	using System;

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

Syntax Explained

NOTE: Every C# statements ends with a semicolon ;

NOTE: C# is case-sensitive; "MyClass" and "myclass" have different meanings

NOTE: Unlike Java, the name of the C# file does not have to match the class name, but they often do (for better organization)

Line 1: using System means we can use classes from the System namespace

Line 3: namespace is used to organise your code and is a container for classes and other namespaces

Line 5: class is a container for data and methods. Every line of code that runs in C# must be inside a class. In this example the class is called Program

Line 9: Console is a class of the System namespace, which has a WriteLine() method that is used to output/print text. In our example, it will output "Hello World!".

If you omit the using System line, you would have to write System.Console.WriteLine() to print/output text.