Saturday 15 March 2014

c# - Why can't var be used in global scope? -



c# - Why can't var be used in global scope? -

this question has reply here:

implicit typing; why local variables? 6 answers

i wondering why c# allows me declare variable using var keyword within method

private somemethod() { var somevariable = 5; }

but not in global scope

public partial class someclass { var somevariable = 5; public someclass() { } }

i've tried googling question , can't find answers.

field initializers can have cyclic dependencies.

how should next code compile?

class { public var = b.b; } class b { public var b = a.a; }

local variables cannot have cyclic initializers, type inference fine.

c# scope var

No comments:

Post a Comment