Steps to Create the Program
1. Open Visual Studio (or your preferred IDE).
2. Create a New Project:
- Select Console App (.NET Core) or Console App (.NET Framework) depending on your setup.
- Give your project a name (e.g., HelloWorldApp).
3. Write the Program in the main file (usually Program.cs).
Example:
//Program.cs file
using System;
class Program
{
static void Main(string[] args)
{
// Print "Hello, World!" to the console
Console.WriteLine("Hello, World!");
}
}
Note: Press Ctrl + F5 (or click Start in Visual Studio) to run the program
Output:
Hello, World!
Explanation:
1. using System: This line imports the System namespace, which includes essential classes like Console used to interact with the console.
2. class Program: Defines a class called Program. In C#, every program must have at least one class.
3. static void Main(string[] args): This is the Main method, the entry point of every C# console application. When you run the program, the Main method is executed first.
4. Console.WriteLine(“Hello, World!”): This line prints the text “Hello, World!” to the console.