This tutorial explains How to write a Hello World First Program in C#

Hello, World Program is a basic Simple First program or application to code and learn any new programming language.

It just displays the hello world string to the console.

This post shows how to write a Hello World application in Dart Programming language.

Prerequisite: Microsoft Visual Studio

Hello World First Program in C

  • First, In Visual Studio, Create a New file,

  • Copy the below code into Hello.cs file

// Hello.cs
using System;
                    
public class Hello
{
    public static void Main()
    {
        Console.WriteLine("Hello World Message printed to console "); // Printing text to Console
    }
}

Following are steps

  • // is a comment in C#

  • First Import .net Inbuilt classes using using keyword

  • Create a class with the name Hello in a file called Hello. cs

  • used using System; in the first line. It is a Directive reference System namespace, similar to Import in Typescript. The system namespace exists in the .NET framework and Superclass. It contains Inbuilt classes such as Console. Using is similar to import in Java.

    In C#, You can import only namespaces, not individual classes.

  • Contains a Main method, which is a Starting Entry point execution when this class is compiled and executed.

    It is a public method which means, It can be called by External classes as well as users. Static is a class-level method, that is called without creating an instance of an object. void is a return type and does return nothing. if this method returns

    The Main method has with or without arguments.

    public static void Main()

if it contains arguments, those are passed as command line arguments as an array.

public static void Main(string [] args )

How to compile and run the C# program

After the above program is created, It is time to compile and run the program.

If you have C# compiler(csc.exe) already installed,

csc Hello.cs

It results in an executable program - Hello.exe file in the current directory.

On running Hello in the terminal, It outputs

Hello.exe