Welcome & Hello World

🔷 C# Programming Lesson 1 Beginner

C# (pronounced "C-Sharp") is a modern, object-oriented, and type-safe programming language developed by Microsoft in 2000. It runs on the .NET framework and is widely used for building enterprise systems, APIs, mobile applications (via Xamarin/MAUI), and game development using the Unity engine.

1 The .NET Compilation Pipeline (CLR, MSIL)

C# does not compile directly to binary machine code. Instead, C# compilations utilize a managed environment:

  • MSIL (Microsoft Intermediate Language): The compiler compiles your C# code into MSIL (a CPU-independent set of instructions).
  • CLR (Common Language Runtime): The execution engine of .NET. The CLR compiles MSIL bytecode into native machine instructions on-the-fly using a Just-In-Time (JIT) compiler.
2 Your First Program: Console.WriteLine()

Let's write a standard C# program template. In C#, every line of code must exist inside a class definition:

C# — Hello World ▶ Run Code
using System;

class Program {
    static void Main() {
        Console.WriteLine("Hello, World!");
        Console.Write("Welcome to Our C# Compiler!");
    }
}

Let's analyze the statements:

  • using System;: Imports the System namespace containing fundamental classes like `Console`.
  • class Program: Declares a class wrapper enclosing our program logic.
  • static void Main(): The entry point method of every C# application. Note that `Main` starts with a capital letter in C#.
  • Console.WriteLine(): Prints text to the screen and automatically appends a newline character.
3 Code Challenge
Challenge: Edit the code in the editor above. Add statements to print your name and a welcome greeting. Ensure you run the code in the compiler to verify.