Originally Posted by
Scorpiona
'var'
is an explicit type. The type is inferred at compile-time, it basically serves as shorthand for making cleaner code where the type is going to be obvious.
ex:
Code:
string myString = "hi";
vs
var myString = "hi";
ref:
var (C# Reference)
'var' is actually an anonymous type declaration. (It's more often used as shorthand though)
Example;
Code:
var person = new {FirstName="Bob", LastName="Hope"};
// do some stuff...
Console.WriteLine(person.FirstName + " " + person.LastName + " is old.");
Notice, I never declared a struct or class to hold the First/LastName vars. Hence the usefulness of anonymous types.