在这些初始化语句编译的前提下
List<int> l = new List<int> { 1, 2, 3 };
Dictionary<int, int> d = new Dictionary<int, int> { [1] = 11, [2] = 22 };
Foo f = new Foo { Bar = new List<int>() };
Run Code Online (Sandbox Code Playgroud)
这不会
List<int> l = { 1, 2, 3 };
Dictionary<int, int> d = { [1] = 11, [2] = 22 };
Foo f = { Bar = new List<int>() };
Run Code Online (Sandbox Code Playgroud)
我有一个关于嵌套初始化的问题.鉴于以下课程
public class Foo {
public List<int> Bar { get; set; } = …Run Code Online (Sandbox Code Playgroud)