C# · Chapter 3.2 · Basic level
Strict Data Types (Player Coins, Health & Weapon)
सख्त डेटा टाइप्स (Coins, Health और Weapon बनाना)
In Python you just wrote coins = 500, but C# is like a disciplined army officer — before creating ANY variable box, you must announce what type of item will go inside it! That's why C# games run blazingly fast:
• int → whole numbers (int coins = 500;, int health = 100;)
• double → decimal numbers (double speed = 5.5;)
• string → text in double quotes (string weapon = "Laser Gun";)
• bool → true or false (bool hasShield = true; — lowercase in C#!)
Python में हम सीधा coins = 500 लिख देते थे, लेकिन C# एक अनुशासित आर्मी ऑफ़िसर जैसा है — यहाँ कोई भी डिब्बा बनाने से पहले बताना पड़ता है कि उसमें किस तरह का सामान रखा जाएगा! इसी वजह से C# गेम्स सुपर-फास्ट चलते हैं:
• int → बिना दशमलव के पूरे नंबर (int coins = 500;)
• double → दशमलव वाले नंबर (double speed = 5.5;)
• string → डबल कोट्स वाला टेक्स्ट (string weapon = "Laser Gun";)
• bool → true या false (C# में छोटे अक्षरों में!)
Words and symbols in this chapter
int coins = 500;- Creates an integer variable
coinsholding500(updates 💰 Coins in Game HUD!). int(पूरा नंबर) टाइप काcoinsडिब्बा बनाता है जिसमें500रखा है।int health = 100;- Sets Hero's HP bar (
0to100) on the 2D Game Stage! - 2D गेम स्टेज पर हीरो की Health Bar (
100) सेट करता है! string weapon = "Laser Gun";- Creates a text variable
weaponequipping the Hero on screen! string(टेक्स्ट) डिब्बा बनाकर हीरो के हाथ में"Laser Gun"थमाता है!double speed = 5.5;- Stores a decimal number (
5.5). - दशमलव संख्या (
5.5) स्टोर करता है। bool hasShield = true;- Stores
trueorfalse(written in lowercase in C#). trueयाfalseस्टोर करता है (C# में छोटे अक्षरों में)।
Ready example
int health = 100;
int coins = 500;
string weapon = "Laser Gun";
Console.WriteLine(coins);
Console.WriteLine(weapon);
What you will see: The 2D Game HUD immediately updates 💰 Coins: 500 and 🔫 Weapon: Laser Gun — try editing 500 to 9999!
2D गेम में हीरो के ऊपर तुरंत 💰 Coins: 500 और 🔫 Weapon: Laser Gun अपडेट हो जाएगा!
Line by line
int health = 100;- Sets player's Health Bar to 100%.
- हीरो की हेल्थ बार को 100 पर सेट करता है।
int coins = 500;- Updates HUD badge to
💰 Coins: 500(try changing500to9999!). - गेम स्क्रीन पर
💰 Coins: 500दिखाता है (9999बदलकर भी देखो!)। string weapon = "Laser Gun";- Equips
🔫 Laser Gunin the Hero's HUD! - हीरो के पास
🔫 Laser Gunहथियार अपडेट करता है! Console.WriteLine(coins); / Console.WriteLine(weapon);- Prints both stats to the game console.
- दोनों स्टेट्स को कंसोल पर प्रिंट करता है।
Common mistake
✗ Wrong
int coins = "100";✓ Right
int coins = 100;int only accepts numbers without quotes; text in quotes belongs in string!
int डिब्बे में कोट्स वाला टेक्स्ट "100" नहीं रख सकते — बिना कोट्स के 100 लिखें!
Your task
Declare int coins = 500; (or any positive number) and string weapon = "Laser Gun";, and print both with Console.WriteLine!
int coins = 500; और string weapon = "Laser Gun"; बनाओ और दोनों को Console.WriteLine से प्रिंट करो!
- Line 1: Write
int coins = 500;.
लाइन 1:int coins = 500;लिखो। - Line 2: Write
string weapon = "Laser Gun";.
लाइन 2:string weapon = "Laser Gun";लिखो। - Print both with
Console.WriteLine(coins);andConsole.WriteLine(weapon);, then Run!
दोनों कोConsole.WriteLineसे प्रिंट करके ▶ Run & Preview दबाओ!
Starter code for the task
int health = 100;
Console.WriteLine("Health: " + health);
// TODO 1: int coins = 500; likho
// TODO 2: string weapon = "Laser Gun"; likho
// TODO 3: dono ko Console.WriteLine(...) se print karoDo this task in the classroom: your code is checked automatically and you get hints if something is missing.
Recap
- C# needs the type before the name:
int coins = 500;. intwhole numbers,doubledecimals,stringtext in" ",booltrue/false.- A value must match its type —
int coins = "100";is a compile error.
- C# में नाम से पहले टाइप लिखना ज़रूरी है:
int coins = 500;। intपूर्ण संख्या,doubleदशमलव,string" "में टेक्स्ट,booltrue/false।- वैल्यू उसके टाइप से मेल खानी चाहिए —
int coins = "100";compile error है।
Quick quiz
Which C# variable declaration is 100% valid?
इनमें से कौन-सा C# वेरिएबल कोड पूरी तरह सही है?
Show the answer
Answer: B (string weapon = "Sword";)
Double-quoted text in C# uses the string type!
C# में टेक्स्ट रखने के लिए string डेटा टाइप का उपयोग होता है!
Practice problems for this chapter
- Game Hero Profile (data types)
गेम हीरो प्रोफ़ाइल (data types)
Solve them in the Practice Zone, where each answer is checked automatically and two hints are available.