Hello World Program in C# - How to Write First Program in C#?

In this tutorial, we will learn how to write first program (Print Hello World) in C#?
By IncludeHelp Last updated : April 06, 2023

Overview

Now let's start C#.Net programming with first C# program that is "print Hello world" which is the first program of all programming languages.

Steps to Write First C#.Net Console Program

Here are the simple steps, how to write first C#.Net console program in Visual Studio.

To write simple console based program. First we need to open Visual Studio, which is an IDE (Integrated Development Environment) for developing application. These are the simple steps:

Step 1) First click on "FILE" menu.

Step 2) Select "New Project" option.

Step 3) Then following window will appear on your screen.

printing hello world in C#.net

Step 4) From the above screen, select language (Visual C#) and then choose Console Application and name the application and choose path to save application. After that Visual studio generates sample code.

print hello world in C#.net

Step 5) In the above program, visual studio automatically add some namespaces. But for "Hello World" application only System namespace is required.

C# program to print Hello World

using System;

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

Output

print hello world in C#.net output on console

Explanation

Here, in this program HelloWorld is the namespace that we created, Namespace may contain many classes but in this program it contains only one class named program and main() is the method of class which is an entry point of the program.




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.