
Day 2: Variables and Data Types
Understand and use variables (placeholders for values) and data types (what kind of value a variable can hold).
๐ Theory (Details)
Variables โ Named storage for values. Example:
int age = 25;Data Types:
intโ whole numbers (e.g., 1, 42)double/floatโ decimal numbers (e.g., 3.14)stringโ text (e.g.,"Hello")boolโ true/false valuesvarโ lets compiler decide the type
String Interpolation โ Combine text + variables easily:
Console.WriteLine($"Hello, {name}. You are {age} years old.");
๐ป Practice
Step 1 โ Create Variables
Edit Program.cs:
string name = "Tuong Vy";
int age = 25;
double height = 1.65;
bool isStudent = true;
Console.WriteLine($"Name: {name}");
Console.WriteLine($"Age: {age}");
Console.WriteLine($"Height: {height}m");
Console.WriteLine($"Student: {isStudent}");
Run โ see output.
Step 2 โ Ask User for Input
Console.Write("Enter your name: ");
string userName = Console.ReadLine();
Console.Write("Enter your age: ");
int userAge = Convert.ToInt32(Console.ReadLine());
Console.WriteLine($"Hello {userName}, you are {userAge} years old!");
Step 3 โ Mini Exercise
Ask user for:
name (string)
favorite number (int)
favorite food (string)
Print back a sentence like:
Hello Vy! Your favorite number is 7 and you like sushi.
