Basic Structure of a C# Program | Hello World Example

Basic Structure of a C# Program | Hello World Example

🚀 Basic Structure of a C# Program

C# is a simple, modern, and type-safe programming language developed by Microsoft. Every C# application starts with a class and a Main() method. Let’s explore the basic structure using a simple Hello World example.

📄 Example: Hello World in C#


using System;

namespace HelloWorldApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, World!");
        }
    }
}
    

📝 Sample Output

Hello, World!

🔍 Explanation

  • using System; – Includes the System namespace which contains basic classes like Console.
  • namespace HelloWorldApp – Organizes code and avoids name conflicts.
  • class Program – Declares a class named Program.
  • static void Main(string[] args) – Entry point of the application. The program starts execution here.
  • Console.WriteLine() – Prints output to the console.

💡 Notes

  • C# is case-sensitive.
  • Every statement ends with a semicolon (;).
  • Code must be inside a class or struct.
  • Main() can also return int instead of void if needed.

Post a Comment

Post a Comment (0)

Previous Post Next Post

ads

ads

Update cookies preferences