小编Mar*_* S.的帖子

C#嵌套初始化陌生感

在这些初始化语句编译的前提下

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)

c# syntax semantics c#-6.0

4
推荐指数
1
解决办法
124
查看次数

标签 统计

c# ×1

c#-6.0 ×1

semantics ×1

syntax ×1