R
Rene
Could someone tell me why is not possible to have Implicitly typed* field
level* variables? For example, why won't the following code compile?
class Program
{
var myString = "abc";
static void Main(string[] args)
{
}
}
If I try to compile this I get the following error: "The contextual keyword
'var' may only appear within a local variable declaration".
Why do I get that error? I mean, if I move the variable declaration inside
the "Main" method things compile perfectly fine so it's obvious that the
compiler is able to infer the type but why does it only work inside a
method?
Thanks.
level* variables? For example, why won't the following code compile?
class Program
{
var myString = "abc";
static void Main(string[] args)
{
}
}
If I try to compile this I get the following error: "The contextual keyword
'var' may only appear within a local variable declaration".
Why do I get that error? I mean, if I move the variable declaration inside
the "Main" method things compile perfectly fine so it's obvious that the
compiler is able to infer the type but why does it only work inside a
method?
Thanks.