Swipe
SwipeSwipe
Swipe Apps

Paths

Motivation

Information

Variables & Primitive Types · Lesson 24 of 27

Primitive Data Types

A free lesson from Swipe Coding · C#, level 2 · updated October 2026

By the Swipe team, founded by Colin · how we make lessons

🤖
A handful of built-in types carry almost all the data in a C# program. 🧮

Every variable in C# needs a type, and the built-in primitive types are the most basic kinds of data a variable can hold. Primitives store a simple value directly, which makes them fast and memory-efficient — unlike the string type you will meet soon, which is a reference type.

int quantity = 10;
double price = 4.99;
bool inStock = true;
char grade = 'A';
Four commonly used primitive types: a whole number, a decimal number, a true/false value, and a single character.
🤖
Four everyday types, four different jobs. 🔡

int stores whole numbers (no decimal point) and is the default choice for counting things. double stores decimal numbers and is the default choice for anything with a fractional part, like prices or measurements. bool can only ever be true or false, which makes it perfect for yes/no conditions — note that C# spells it bool, not boolean. char stores exactly one character, written in single quotes like 'A' — never double quotes, which are reserved for strings.

Fill in the blank

To store a single character like 'A', you use the ____ type.

C# also has smaller and larger whole-number types for when int isn't the right fit: byte and short save memory for tiny numbers, while long is used for whole numbers bigger than int can hold — you mark a long literal with an L at the end. For money and other values needing exact decimal precision, C# offers decimal, marked with an m suffix; it is more precise than double but slightly slower to calculate with.

long population = 8_000_000_000L;
byte smallNumber = 120;
decimal price = 19.99m;
long needs an L suffix and decimal needs an m suffix on their literal values; byte is useful for very small numbers where saving memory matters.
🤖
Local variables don't get the same free pass as fields — keep that in mind here. 🤔

Fields that belong to a class automatically get a default value if you don't initialize them — 0 for numeric types, false for bool, and a null character for char. Local variables declared inside a method, however, do not get a default value: the compiler forces you to assign one before you can use the variable, which helps catch bugs early.

True or false

A local variable declared inside a method automatically gets a default value, like 0, if you never initialize it.

Quick check

Which primitive type would you use to store whether a light switch is on or off?

Chapter quiz

Variables & Primitive Types

10 questions · pass with 60% — just like in the app.

Quick check

What must every variable in C# have?

True or false

In C#, variable names are case-sensitive, so score and Score are different variables.

Fill in the blank

C#'s naming convention for local variables is ____, e.g. totalScore.

Quick check

Which statement correctly declares and initializes an int variable named age?

True or false

You can declare a variable without giving it a value right away, as long as you assign one before using it.

Fill in the blank

The ____ type stores whole numbers and is the most common choice for counting things.

Quick check

Which type would you use to store a value like 4.99?

True or false

A local variable inside a method automatically receives a default value if you don't initialize it.

Fill in the blank

A long literal in C# must end with the letter ____.

Quick check

What happens when you reassign a variable that already holds a value?

Keep your streak going in Swipe Coding

Swipe through every level of C# on your iPhone — with XP, stars, streaks, a personal advisor and the full track beyond these free levels.

Get the Swipe apps →