Skip to content
AgileLogics
5 min read

Variables & Data Types

Prerequisites: How C# code runs

Syntax

int age = 36;
double price = 19.99;
bool isActive = true;
char grade = 'A';
string name = "Ada";

Example

int score = 10;
Console.WriteLine(score);
score = 20;
Console.WriteLine(score);

Expected output

10
20

Use const for a compile-time constant, similar to Java's final:

const int MaxScore = 100;

Common mistakes

  • Assigning a value of the wrong type without conversion — this is a compile error, not something C# quietly coerces.

Practice

Declare a const string called cityName holding your city's name, then print it.

Show solution
const string cityName = "Lagos";
Console.WriteLine(cityName);