var

noun

say it: “VAR” /vɑːr/

A C# keyword that lets the compiler work out a local variable's type from the value you give it.

What is var in C#?

var — A keyword asking the compiler to infer a local variable's type from its value.

class City
{
    void NormalizeName()
    {
        var name = "Denver";
        var uppercaseName = name.ToUpper();
    }
}

In a sentence

  • “I wrote var total = 0m; and the compiler knew total is a decimal.”

Level: Apprentice · More C# terms at this level

Updated

In other subjects