Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't i declare a field using var [duplicate]

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
    }
}
like image 810
George Duckett Avatar asked Jan 21 '26 19:01

George Duckett


1 Answers

Straight from the source:

Why no var on fields?

like image 166
jason Avatar answered Jan 23 '26 08:01

jason



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!