Explain it simply
Variables, in plain language
A variable is basically a little box that holds data. In C#, you have to specify the data type before declaring a variable. That way, the compiler can catch data type mistakes while you're still writing the code.
Problem → Why → Solution
The problem — why this concept matters
Failing to distinguish an uninitialized or default value from a valid domain value creates zero, false, and null bugs.
A common mistake
Assuming one successful happy path proves the code is correct, maintainable, and production-ready.
Core concept — understand how it works
A variable has a name, compile-time type, scope, lifetime, and current value. `var` is compile-time inference rather than dynamic typing; use `const`, nullable annotations, and the smallest useful scope deliberately.
- typed input
- C# expression and method
- CLR value or object state
Explain the core concept and runtime behavior of Variables
Core syntax or pattern
string name = "Aung";
int age = 30;
double height = 5.8;
bool isStudent = false;
Console.WriteLine("Name: " + name);
Console.WriteLine($"Age: {age}");
Console.WriteLine($"Height: {height}");
Console.WriteLine($"Student: {isStudent}");A variable has a name, compile-time type, scope, lifetime, and current value. `var` is compile-time inference rather than dynamic typing; use `const`, nullable annotations, and the smallest useful scope deliberately.
Read the code step by step
- typed input
string name = "Aung";A variable is basically a little box that holds data. In C#, you have to specify the data type before declaring a variable. That way, the compiler can catch data type mistakes while you're still writing the code.
- C# expression and method
Console.WriteLine("Name: " + name);A variable has a name, compile-time type, scope, lifetime, and current value. `var` is compile-time inference rather than dynamic typing; use `const`, nullable annotations, and the smallest useful scope deliberately.
- CLR value or object state
Console.WriteLine($"Student: {isStudent}");Read an age as text, validate it with `int.TryParse`, and test both success and failure branches.
- typed input
- C# expression and method
- CLR value or object state
Success
Explain the core concept and runtime behavior of Variables
Failure
Failing to distinguish an uninitialized or default value from a valid domain value creates zero, false, and null bugs.
A variable is basically a little box that holds data. In C#, you have to specify the data type before declaring a variable. That way, the compiler can catch data type mistakes while you're still writing the code.
string name = "Aung";
int age = 30;
double height = 5.8;
bool isStudent = false;
Console.WriteLine("Name: " + name);
Console.WriteLine($"Age: {age}");
Console.WriteLine($"Height: {height}");
Console.WriteLine($"Student: {isStudent}");What this code does
stringholds text.intholds whole numbers.doubleholds decimal numbers.boolholdstrueorfalse.$"Age: {age}"is string interpolation — a cleaner way to drop a variable's value into a string.
Name: Aung Age: 30 Height: 5.8 Student: FalseInfo
⚠️ Common mistake
int age = "30"; will throw an error. "30" is text, while 30 is a number. Whether or not you add quotes changes the data type entirely.
Real-world usage
How to apply it in a real project
Read an age as text, validate it with `int.TryParse`, and test both success and failure branches.
Mini challenge
Build it yourself
Read an age as text, validate it with `int.TryParse`, and test both success and failure branches.
- Rebuild the example without copying it
- Test a normal input and an edge case
- Predict the compiler or output result before running it
string name = "Aung";
int age = 30;
double height = 5.8;
bool isStudent = false;
Console.WriteLine("Name: " + name);
Console.WriteLine($"Age: {age}");
Console.WriteLine($"Height: {height}");
Console.WriteLine($"Student: {isStudent}");Expected: Explain the core concept and runtime behavior of Variables
Show hint
Read an age as text, validate it with `int.TryParse`, and test both success and failure branches.
Quick quiz 1 / 3
Quick quiz 2 / 3
Quick quiz 3 / 3
What to remember
- typed input → C# expression and method → CLR value or object state
- A variable has a name, compile-time type, scope, lifetime, and current value. `var` is compile-time inference rather than dynamic typing; use `const`, nullable annotations, and the smallest useful scope deliberately.
- Failing to distinguish an uninitialized or default value from a valid domain value creates zero, false, and null bugs.
- Read an age as text, validate it with `int.TryParse`, and test both success and failure branches.
C# documentation — Microsoft Learn