Question

Difference between "var" and "object" in C#

Is the var type an equivalent to Variant in VB? When object can accept any datatype, what is the difference between those two?

 45  33039  45
1 Jan 1970

Solution

 53

Beginning in Visual C# 3.0, variables that are declared at method scope can have an implicit type var. An implicitly typed local variable is strongly typed just as if you had declared the type yourself, but the compiler determines the type. The following two declarations of i are functionally equivalent:

var i = 10; //implicitly typed
int i = 10; //explicitly typed

var isn't object

You should definitely read this : C# 3.0 - Var Isn't Object

2009-10-12