C# Hello World
The Hello World Program is the most basic program when we dive into a new programming language. This simply prints "Hello World!" on the console. In C#, a basic program consists of the following:
- A Namespace Declaration
- Class Declaration & Definition
- Class Members(like variables, methods, etc.)
- Main Method
- Statements or Expressions
Example: Hello World program in C#.
using System;
namespace HelloWorldApp {
class Geeks {
static void Main(string[] args) {
// statement printing Hello World!
Console.WriteLine("Hello World!");
// To prevent the screen from running and closing quickly
Console.ReadKey();
}
}
}
using System; namespace HelloWorldApp { class Geeks { static void Main(string[] args) { // statement printing Hello World! Console.WriteLine("Hello World!"); // To prevent the screen from running and closing quickly Console.ReadKey(); } } }Output
Hello World!
Explanation:
This program is a simple C# console application that prints Hello World to the screen. Every C# program starts execution from the Main method.
- using System: allows access to built-in classes like Console.
- namespace HelloWorldApp: groups the class logically under a namespace.
Inside the namespace, we define a class Geeks which contains the Main method. The Main method is special because it acts as the entry point for the program.
- Console.WriteLine("Hello World!"): prints text to the console.
- Console.ReadKey(): waits for a key press so the program doesn’t close immediately.
Executing C# Program
There are generally three ways to compile and execute a C# program.
- Online Compiler: Run C# programs directly in a browser without installation.
- IDE (Visual Studio): Microsoft’s powerful IDE with built-in tools for C# development.
- Command Line: Install the .NET SDK to compile and run C# programs locally.
Now follow the below steps:
Step 1: Open a command prompt and create an empty .NET project using the following command:
dotnet new console -o <Project-Name>
In <Project-Name>, specify the desired project name (e.g., HelloWorld). This command creates an empty project template with all required packages to run a .NET project.

This is the complete folder structure which is created using the above command.

Program.cs is the entry point of a C# project where the main code is written. It can be opened in IDEs like Visual Studio or VS Code and contains the default starter code for the application.

This is a simple program we can run it using the following command mentioned in the below steps.
Step 2: Now we need to build the project using the command mentioned below.
Navigate to the project directory:
cd HelloWorld
Build the project using:
dotnet build

Step 3: Now to see the output run the command mentioned below.
dotnet run

This will execute the default Program.cs file and display output in the console.