As opposed to using the
var
keyword, you can use the
Object
keyword.
The object type is an alias for
Object
in the .NET Framework. In the unified type system of C#, all types, predefined and user-defined, reference types and value types, inherit directly or indirectly from Object. You can assign values of any type to variables of type object. When a variable of a value type is converted to object, it is said to be boxed. When a variable of type object is converted to a value type, it is said to be unboxed.
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.
Using .Net framework 3.0 and higher you'll use
var myVar = new UnknownType();
Using .Net framework lower than 3.0, you'll use
object myVar = new UnknownType();