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:
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.
First C# Program – Interview Questions
Q 1: What is the entry point of a C# program?
Q 2: Which namespace is required for basic input/output?
Q 3: What does Console.WriteLine() do?
Q 4: What file extension is used for C# programs?
Q 5: What keyword is used to define a class?
First C# Program – Objective Questions (MCQs)
Q1. Which method is the entry point of a C# program?
Q2. Which statement is used to display output in C# console applications?
Q3. Which namespace is commonly used in a basic C# program?
Q4. What is the correct file extension for a C# code file?
Q5. Which keyword is used to define a namespace?