C# Syntax

In this lesson, you will learn about the syntax of a program in the C# programming language by creating a simple, yet famous program called “Hello World!”


C# Program Syntax Explain

Before you get started, let’s create a simple program in C#. Use the Project we created in the previous lesson, then add the code below to the Program.cs file:

The program above output the string “Hello World!” to the console.


Structure of the C# program

  • using System: namespace used in this example
  • class Learnmodo: class name that contains the program
  • static void Main(string[] args): The program’s entry point.
  • First open bracket {: the open bracket for the class Learnmodo.
  • Second open bracket {: the open bracket for the function Main.
  • Console.WriteLine("Hello World!"); : The statement that print Hello World!, using the WriteLine function.
  • First close bracket }: the close bracket for the function Main.
  • The second close bracket }: the close bracket for the class Learnmodo.

As you can see, classes and functions code are enclosed between two brackets {}. Program statement always ends with the semi-column;

Keep in mind that C# is case sensitive, so console is not the same as Console.

Note
We will discuss the terms function, namespace, and class in detail later in this course.

This is the simplest form of programs in C#. In the next lesson, you will learn about different types of Comments in C# and their usage.

Lesson Content