c# - Why cannot an implicitly typed variable be declared at class level? -


this question has answer here:

so code below valid , outputs 5 excpected , type of foo inferred system.int32.

class program {     static void main()     {         var foo = 5;        console.writeline(foo);     } } 

but if write this

class program {     static var foo = 5;      static void main()     {         console.writeline(foo);     } } 

you following error:

the contextual keyword 'var' may appear within local variable declaration.

what problem of declaring variable using var-keyword @ class level? don't quite understand this, can make clear?

well 1 reason var cannot accessed outside scope had declared , , static persists , can accessed globally(here can see conflicts of intrests) , there goes answer can not declare var static.
implicitly typed local variables


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -