The var
keyword allows me to declare typed variables, and allows the variables to be defined implicitly.
Example: var i = 10;
The compiler will assume that my variable i
is integer type int
.
So, why does not the compiler allow me to use the var
keyword for attribute declarations within a class?
See this example for illustration:
class ClasseExemplo
{
public var atributo; //Este atributo poderia ser declarado de forma implícita.
public ClasseExemplo()
{
this.atributo = null;
}
}
The above example returns the following error:
Error 1 The type or namespace name 'var' could not be found missing a using directive or an assembly reference?)
If this way I can not declare an attribute that can be of any type , could there be another way to do this?