2

Possible Duplicate:
Why class fields cannot be var?

I'd like to avoid typing out complex/long type definitions for fields like you can with local variables.

I'd like to know why this couldn't be done?

public class Foo
{
    public var barField = new Dictionary<string, int>(); // Does not work

    public void Method()
    {
        var barLocal = new Dictionary<string, int>(); // Works
    }
}
Community
  • 1
  • 1
George Duckett
  • 31,770
  • 9
  • 95
  • 162

2 Answers2

9

Straight from the source:

Why no var on fields?

jason
  • 236,483
  • 35
  • 423
  • 525
0

You can't have global vars. Please check the remarks section of http://msdn.microsoft.com/en-us/library/bb384061.aspx