find and solve || findandsolve.com
Please wait.....

C# Hello World Program

Download source

The Hello World! program is the most basic and first program in the c# programming language. In this blog, we will try to focus on the basic syntax and requirements of a C# programming language. "Hello World!" in C#.

The focus of this c# program is to get us familiar with the basic syntax and requirements of a programming language.

First,  download and install Visual Studio on Windows Machine and open your visual studio.

Create a C# Console Application

  • Open your visual studio 2019 or greater than 2019
  • Click on Create a New Project
  • Select Console Application and then Next
  • Provide a Project name and confirm or change the Location. Click Next


  • Select the Target Framework under drop-down (.NET Core 5.0)and Click on Create button.

Once you click on the Create button, a new console application will be created as given below. In case the Program.cs file not opened in your code editor, open Solution Explorer menu on the right side and open your Program.cs file code by double-clicking it.


Hello World Example in C#

using System;  

// namespace declaration
namespace HelloWordInCsharp {
    // declaration class here
    public class FindAndSolve {
        // This is Main Method
        public static void Main(string[] args) {
            // statement
            // printing Hello World!
            Console.WriteLine("Hello World!");
            // To prevents the screen from
            // running and closing quickly
            Console.ReadKey();
        }
    }
}

Output



Explanation Given Above Example

  • using System: System is a namespace that contains the commonly used types. It is specified with a using System directive.
  • namespace HelloWordInCsharp: namespace is the keyword that is used to define the namespace. HelloWordInCsharpis the user-defined name given to namespace. For more details, C# Namespaces
  • class FindAndSolve: class is the keyword that is used for the declaration of classes. FindAndSolve is the user-defined name of the class.
  • static void Main(string[] args): Main() is a method of class FindAndSolve. The execution of every C# program starts from the Main() method. 
  • Console.WriteLine(): WriteLine() is a method of the Console class defined in the System namespace.
  • Console.ReadKey(): This is for the VS.NET Users. This makes the program wait for a keypress and prevents the screen from running and closing quickly.

Things to remember from this article

  • Every C# program language must have a class definition.
  • The execution of the program begins from the Main() method.
  • Main() method must be inside a class definition.

This is just a simple program for introducing C# to a newbie. If you did not understand certain things in this article, that's okay (even I did not when I started). As we move on with this tutorial series, everything will start to make sense.