Alex Rivera | Logout

var: a Type or a keyword

Asked 2010-09-11T07:52:14.700
10

MSDN categorizes var under Types.

variables that are declared at method scope can have an implicit type var

what does 'implicit type var' mean in this context?

Strictly said, if I have it to explain to fellow programmers.

Can I say; var is a Type, or do I have to say; var is a keyword that instructs the compiler to determine the type itself.

note: this is not meant to start a discussion about var, nor to learn the use of var. For once and for all I want to know excactly how to describe it and msdn is a bit confusing, that's it.

Edit
Report

1 Answer

0

var is a Type, like int is ... but what Type is it exactly??

Well, the compiler works that out for you (which is what implicitly means) based on the rest of the line.

e.g.

var b = "ahjhsad";

At compile time, var will be replaced with string.

var is used as a convenient short hand for the programmer, instead of having to write

List<string> myList = new List<string>();

a programmer can write

var myList = new List<string>();

and it means the same thing.

answered 2010-09-11T08:02:08.923

Your Answer