VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/c-sharp-hello-world/

โ‡ฑ C# Hello World - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C# Hello World

Last Updated : 4 Sep, 2025

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#.


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.

๐Ÿ‘ DotNETProjectCreation

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

๐Ÿ‘ FolderStructure


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.

๐Ÿ‘ FolderStructure

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

๐Ÿ‘ dotNETBuildCMD

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

dotnet run

๐Ÿ‘ DotnetRunCMD

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

Comment
Article Tags:
Article Tags:

Explore