Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

var keyword runtime or compile time?

Tags:

variables

c#

.net

var keyword gets the type at the runtime or compile time?

or depends?

like image 822
DarthVader Avatar asked Sep 03 '10 03:09

DarthVader


3 Answers

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)

like image 198
Leniel Maccaferri Avatar answered Sep 21 '22 01:09

Leniel Maccaferri


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

http://msdn.microsoft.com/en-us/library/bb383973.aspx

like image 4
anishMarokey Avatar answered Sep 21 '22 01:09

anishMarokey


The var keyword is implicitly typed. This means that it is strongly typed, but the compiler determines the type.

like image 1
Rebecca Chernoff Avatar answered Sep 21 '22 01:09

Rebecca Chernoff