A variable is a named place in memory that stores a value. In C#, every variable has a data type, and the type determines the range of values it can hold. A single equals sign assigns a value, while a double equals sign compares two values and gives a bool result, true or false.
Variable names must follow rules. A name cannot start with a digit, cannot contain spaces, and is case-sensitive in C#. A local variable must be given a value before it is used, or the compiler reports an error. A string is a reference type, and its value is stored in a separate memory area.
Inside your account
What an account adds to the pages you are reading.
Lessons
Topic explanations with worked examples, split into units.
A single equals sign assigns a value; a double equals sign compares two values and returns a bool.
Variable names cannot begin with a digit or contain spaces, and C# is case-sensitive.
A local variable must be assigned a value before it is used.
Converting a double to an int truncates the decimal part: 9.7 becomes 9.
Bytes, kilobytes and megabytes are linked by powers of 1024, and bandwidth is usually given in bits per second.
Example
Question: an IPv4 address has four octets, and each octet has 8 bits. What is the largest value one octet can hold, and how many values does it represent? The largest value is 255, and the range runs from 0 to 255, which gives 256 possible values.
Question: a 4 GB portable disk holds a 750 MB image file. How many MB of unused space remain? Since 4 GB equals 4096 MB, subtracting 750 MB leaves 3346 MB of unused space.
Common mistakes
Treating megabit and megabyte as the same. A 100 Mbit/s connection transfers 100 / 8 = 12.5 MB per second, not 100 MB.
Using a local variable before it has a value. C# reports an error when this happens.
Confusing assignment with comparison. In if (durum = true), a single equals sign assigns a value, so the condition is always true and the error stays hidden.
Summary
Variables hold values and operators work on them. In C#, the single equals sign assigns, the double equals sign compares, and integer division and modulus behave differently from decimal division. Bit and byte conversions matter for bandwidth and storage calculations, and the valid range of an IPv4 octet is 0 to 255.