Can a class property/field be of anonymous type in C# 4.0?

后端 未结 7 1755
后悔当初
后悔当初 2021-01-18 02:53

As in:

public class MyClass {

  private static var MyProp = new {item1 = \"a\", item2 = \"b\"};

}

Note: The above doesn\'t compile nor wo

7条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-18 03:25

    In C# 7 you can finally do this:

    private (string Login, string Password) _credentials = (Login: "123", Password: "123");
    

提交回复
热议问题