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# में छोटे अक्षरों में!)

In the classroom you can run and edit this code in your browser, get hints and mark the chapter as done. क्लास में यह code ब्राउज़र में चलाकर बदल सकते हो।

Words and symbols in this chapter

int coins = 500;
Creates an integer variable coins holding 500 (updates 💰 Coins in Game HUD!).
int (पूरा नंबर) टाइप का coins डिब्बा बनाता है जिसमें 500 रखा है।
int health = 100;
Sets Hero's HP bar (0 to 100) on the 2D Game Stage!
2D गेम स्टेज पर हीरो की Health Bar (100) सेट करता है!
string weapon = "Laser Gun";
Creates a text variable weapon equipping the Hero on screen!
string (टेक्स्ट) डिब्बा बनाकर हीरो के हाथ में "Laser Gun" थमाता है!
double speed = 5.5;
Stores a decimal number (5.5).
दशमलव संख्या (5.5) स्टोर करता है।
bool hasShield = true;
Stores true or false (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 changing 500 to 9999!).
गेम स्क्रीन पर 💰 Coins: 500 दिखाता है (9999 बदलकर भी देखो!)।
string weapon = "Laser Gun";
Equips 🔫 Laser Gun in 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 से प्रिंट करो!

  1. Line 1: Write int coins = 500;.
    लाइन 1: int coins = 500; लिखो।
  2. Line 2: Write string weapon = "Laser Gun";.
    लाइन 2: string weapon = "Laser Gun"; लिखो।
  3. Print both with Console.WriteLine(coins); and Console.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 karo

Do this task in the classroom: your code is checked automatically and you get hints if something is missing.

Recap

Quick quiz

Which C# variable declaration is 100% valid?

इनमें से कौन-सा C# वेरिएबल कोड पूरी तरह सही है?

  1. int weapon = "Sword";
  2. string weapon = "Sword";
  3. bool coins = 50;
  4. text name = "Raj";
Show the answer

Answer: B (string weapon = "Sword";)

Double-quoted text in C# uses the string type!

C# में टेक्स्ट रखने के लिए string डेटा टाइप का उपयोग होता है!

Practice problems for this chapter

Solve them in the Practice Zone, where each answer is checked automatically and two hints are available.