Skip to content

Type Inference with var

The var keyword lets the compiler infer the type from the initialisation expression.

var number = 10; // int
var text = "Hi"; // string
var pi = 3.14; // double
Console.WriteLine($"{number}, {text}, {pi}");
Terminal window
dotnet run
Terminal window
10, Hi, 3.14