var keyword gets the type at the runtime or compile time?
or depends?
var keyword gets the type at the runtime or compile time?
or depends?
Plain and simple: compile time
var
isn't a type. The actual type is figured out at compile-time.
var
variables are also known as Implicitly Typed Local Variables (C# Programming Guide)
var type gets at compile time
.
Var is an implicitly typed local variable is strongly typed just as if you had declared the type yourself, but the compiler determines the type
var i = 10; // implicitly typed
int i = 10; //explicitly typed
The var keyword is implicitly typed. This means that it is strongly typed, but the compiler determines the type.