C# 如何声明在一条语句中指定元素的二维和三维列表?
有人能告诉我如何声明2D和3DC# 如何声明在一条语句中指定元素的二维和三维列表?,c#,list,declaration,C#,List,Declaration,有人能告诉我如何声明2D和3D列表,并在一条语句中指定元素吗?我不想以后再申报。列表对象将保持不变 这是我尝试使用3D列表的结果,但它不正确: List<string[][]> List_3D = new List<string[][]> { { new string[][] { new string[] { "A", "B", "C" },
列表
,并在一条语句中指定元素吗?我不想以后再申报。列表
对象将保持不变
这是我尝试使用3D列表的结果,但它不正确:
List<string[][]> List_3D = new List<string[][]> { { new string[][] { new string[] { "A", "B", "C" },
new string[] { "D", "E", "F" } },
new string[] { "1", "2", "3" },
new string[] { "4", "5", "6" } };
List List_3D=new List{{new string[][]{new string[]{“A”、“B”、“C”},
新字符串[]{“D”,“E”,“F”},
新字符串[]{“1”、“2”、“3”},
新字符串[]{“4”、“5”、“6”};
您只需要在一条语句中声明它们,就像这样
public List<String> foo = new List<String> { "a", "b", "c" };
public List<List<String>> foo2D = new List<List<string>>
{
new List<String> {"a", "b", "c"},
new List<String> {"d", "e", "f"}
};
public List<List<List<String>>> foo3D = new List<List<List<string>>>
{
new List<List<String>>
{
new List<String> {"a", "b", "c"},
new List<String> {"d", "e", "f"}
},
new List<List<String>>
{
new List<String> {"g", "h", "i"},
new List<String> {"j", "k", "l"}
}
};
public List foo=新列表{“a”、“b”、“c”};
public List foodd=新列表
{
新名单{“a”、“b”、“c”},
新名单{“d”、“e”、“f”}
};
public List foo3D=新列表
{
新名单
{
新名单{“a”、“b”、“c”},
新名单{“d”、“e”、“f”}
},
新名单
{
新列表{“g”、“h”、“i”},
新列表{“j”、“k”、“l”}
}
};
编辑
好奇的是,如何用内部字符串[][]声明外部列表 里面 基本上相同的概念,只是用数组替换列表:
public List<String[][]> fooString2D = new List<String[][]>
{
new String[][]
{
new String[] {"a", "b", "c"},
new String[] {"d", "e", "f"}
},
new String[][]
{
new String[] {"g", "h", "i"},
new String[] {"j", "k", "l"}
}
};
public List fooString2D=新列表
{
新字符串[][]
{
新字符串[]{“a”、“b”、“c”},
新字符串[]{“d”、“e”、“f”}
},
新字符串[][]
{
新字符串[]{“g”、“h”、“i”},
新字符串[]{“j”、“k”、“l”}
}
};
您的特定代码有哪些地方不正确:
- 它的开头有一个额外的
{
- 它缺少第二个
声明新字符串[][]
- 它需要一个额外的
}
List<int> myList = new List<int>
{
1,
2,
3
};
List myList=新列表
{
1.
2.
3.
};
@entropic我已经编辑了我的问题,以显示我想做什么。看起来chancea在评论中击败了我。我相信这就是你要寻找的。我想我必须阅读更多关于好奇的内容,你如何声明内部字符串为[][]的外部列表?