AnyCompiler

Aapka Pehla C# Program

Har C# program ko ek class chahiye jisme static void Main() method ho — yahi se execution shuru hota hai. Top par using System; likhne se System namespace import hota hai, jisse aapko Console access karne ke liye har baar uska full name (System.Console) likhne ki zaroorat nahi padti.

Pehle Compiling Hoti Hai

Jab aap run dabate hain, compiler pehle aapki poori file check karta hai aur compile karta hai, tab ja kar ek bhi line execute hoti hai. Agar kahin bhi type error ya syntax mistake ho, to kuch bhi run nahi hota — output ki jagah aapko compiler error milta hai.

Comments

Comments zyada tar C-family languages jaisa hi kaam karte hain: // ke baad line par jo kuch bhi likha ho wo mukammal taur par ignore ho jata hai — iska maqsad sirf ye hota hai ke baad mein code parhne wale insaan ko samajh aaye ke kuch is tarah kyun likha gaya hai.

Khud Chala Kar Dekho

Ye hai ek chhota program jisme ek comment aur do Console.WriteLine calls hain. Ye waqai execute kiya gaya tha neeche dikhaye gaye output ko lane ke liye — example ke neeche diye gaye button se text badal kar khud chala kar dekhein.

using System;

class Program {
    static void Main() {
        // This is a comment -- ignored by the compiler
        Console.WriteLine("Hello, world!");
        Console.WriteLine("Learning C# one step at a time.");
    }
}
Output
Hello, world!
Learning C# one step at a time.

Aage: variables aur types — primitive types, var inference, aur ek real type-mismatch compile error kaisa dikhta hai.

Practice exercise

Apne code ke upar ek comment add karein, phir "Learning C# one step at a time." print karein.