1. Variables and Boxes
Variables are these special things for storing data. Any kind of data. All data in C# is stored using variables. A variable is basically like a box: just a regular box.
Let's say you write the number 13 on a piece of paper and put that paper in a box. Now we can say that “the box stores the value 13”.

Every variable in C# has three important properties: type, name, and value.
Name is used to tell one variable from another. It's like a label on the box.
The type of a variable defines the kind of values/data you can store in it. Cake goes in a cake box, shoes go in a shoe box, and so on.
Value is just some object, data, or info that's stored in the variable.
Every object in C# has its own type. For example, you can have data types like: integer, floating-point number, text, Cat type, House type, and so on.
Each variable (box) also has its own type. A variable can only store values of the same type as itself. Different boxes are used to store different things: a candy box, an egg carton, etc. Just like in real life.
2. Creating a Variable
In C#, to create a variable, you use a command like this:
type name;
Where type is the type of the variable (matches the type of values the variable can store). And name is the variable's name.
Examples:
| Creating a variable: first the type, then the name. | Description |
|---|---|
|
We create a variable named a of type int. |
|
We create a variable named s of type string. |
|
We create a variable named c of type double. |
The two most common types are integers (written as int) and text (written as string). The double type is also popular — that's for floating-point (real) numbers.
3. Assignment
Like we said before, a variable has a name, type, and value. We've already covered name and type, but what about value? How do you put a value into a variable?
To put a value into a variable, there's a special operation — the assignment operation. It copies a value from one variable to another. It doesn't move it, it copies it. Like a file on your drive. Assignment looks like this:
name = value;
Where name is the variable's name, and value is the value that will be put into the variable. The value can be a literal, another variable's name, or even some expression using variables.
Examples:
| Code | Description |
|---|---|
|
Variable i is createdVariables a, b are createdVariable x is created |
|
The value 3 is put into variable i. |
|
The value 1 is put into variable a. The value 2 is put into variable b. |
|
The value 3 is put into variable x. In the next line, the value of x increases by 1, so x is now 4. |
The assignment operation uses the equals sign =. This is not comparison. It's literally a command to copy the value on the right of the equals sign into the variable on the left. For comparison in C#, you use double equals ==.
4. Variable Name: What You Can and Can't Do
Here are some facts you'll want to know when creating variables:
- The variable name can be anything (for example, temperature, score, userAge).
- But there are limits — it can't start with a digit, and it can't be the same as a C# keyword (for example, you can't name a variable int or if).
- It can't have special symbols, except for $ and _.
- Case matters in the name (
Ageandageare different variables). - Usually,
camelCasestyle is used: first letter is lowercase, then each word starts with a capital (userAge,maxScore).
Examples of allowed names:
int x123 = 1;
string kitten;
double PI = 3.14;
string MAIN_PATH = "c:/";
Examples of forbidden names:
int 1first = 1; // name can't start with a digit
int number# = 25; // # symbol can't be used in a name
string name" = "John"; // quotes aren't allowed in a name
double pi+e = 5.123'; // name can't have +
You'll find out everything else in future lectures. Now a logic question: how many steps does it take to catch a cat in a box?
5. Cats and Boxes

How to catch a cat:
- Take an empty box.
- Wait.
Just kidding 🙂
Well, maybe you can stuff as many cats as you want into a box, but in a variable you can only put one value. And that's what the next task is about.
GO TO FULL VERSION