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 ho, compiler pehle aapki poori file check karta hai aur compile karta hai, tab jaake ek bhi line execute hoti hai. Agar kahin bhi type error ya syntax mistake ho, to kuch bhi run nahi hota — output ke jagah aapko compiler error milta hai.
Comments
Comments zyadatar C-family languages jaisa hi kaam karte hain: // ke baad line par jo kuch bhi likha ho wo completely ignore ho jata hai — iska maqsad sirf ye hota hai ki baad mein code padhne wale insaan ko samajh aaye ki kuch is tarah kyun likha gaya hai.
Khud run karo
Ye hai ek chhota program jisme ek comment aur do Console.WriteLine calls hain. Ye actually execute kiya gaya tha neeche dikhaye gaye output ko lane ke liye — example ke neeche diye button se text badal kar khud run karke dekho.
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.");
}
}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 karo, phir "Learning C# one step at a time." print karo.