var in C# - Why can't it be used as a member variable? [duplicate]
Asked Answered
O

1

11

Why is it not possible to have implicitly-typed variables at a class level within C# for when these variables are immediately assigned?

ie:

public class TheClass
{
    private var aList = new List<string>();
}

Is it just something that hasn't been implemented or is there a conceptual/technical reason for why it hasn't been done?

Ortega answered 5/5, 2010 at 8:8 Comment(2)
That's called a field, not a member variable.Joline
I thought they meant the same thing, one is from Java and the other from C++.Ortega
M
12

Here's a blog post from Eric that explains the reasoning.

Minnow answered 5/5, 2010 at 8:10 Comment(1)
Ah that's a great blog - thanksOrtega

© 2022 - 2024 — McMap. All rights reserved.