WeCodeAcademy

C# Variables and Types

C# is strongly typed. Common types: int, double, bool, char, string. var lets the compiler work out the type, and const makes a constant.

ExampleC#
using System;

class Program
{
    static void Main()
    {
        string name = "Ada";
        int age = 36;
        bool student = false;
        char grade = 'A';
        const int Year = 2026;
        var count = 10;

        Console.WriteLine(name + " is " + age);
        Console.WriteLine($"{name}: grade {grade}, student {student}");
        Console.WriteLine($"{Year} {count}");
        age = 37;
        Console.WriteLine(age);
    }
}
Output
Ada is 36
Ada: grade A, student False
2026 10
37

The $"..." form is string interpolation: expressions inside braces are inserted into the text. Note that bool values print as True and False.

Quick check

What does $"{name} is {age}" do?

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.