Skip to content
dreamcode
dreamcode
Map
Variables & types
Lesson 2 of 21
+15 XP on finish
C# FOUNDATIONSChapter 1 · C# Foundations

Variables and types

C# is statically typed, so every variable has a type. Use int for whole numbers, string for text in double quotes, and bool for true or false. The keyword var lets the compiler infer the type for you.

Worked example
int stars = 100;
string sky = "neon";
bool isClear = true;
var mood = "dreamy";

Console.WriteLine(stars);
Console.WriteLine(sky);

How it reads

  • int stars = 100; declares a whole-number variable named stars
  • string sky = "neon"; holds text, always in double quotes
  • var mood lets the compiler infer the type from the value
Cloud tip: In C#, double quotes make a string and single quotes make a single char. They are not interchangeable.

Check your understanding

0 / 3

Answer all 3 to complete this lesson and earn 15 XP.

  1. 1. Which type holds whole numbers?
  2. 2. How do you write a text (string) value in C#?
  3. 3. What does the var keyword do?
Answer every question to unlock the next lesson.