C#中List的2维数组?

Mat*_*Bai 5 c# arrays list

我只想在c#中获得List的2维数组.在我的想法中,下面应该有效,但它没有,List的1维数组有效.我将Unity3D与Mono一起使用,但我认为这是与语言相关的问题.

List<MyType>[,] twoDArrayofList;//don't work, it's type is List<MyType>
List<MyType>[] oneDArrayofList;//it's works, the type is List<MyType>
Run Code Online (Sandbox Code Playgroud)

谁知道什么是错的?谢谢.

Dam*_*Arh 6

你是什​​么意思"不工作"?你遇到了什么错误?

我不知道Mono(或Unity3D),但我只是在.NET项目中尝试了以下内容并得到了我期望的结果:

List<string>[,] strings = new List<string>[2, 2];
strings[0, 0] = new List<string> { "One" };
strings[0, 1] = new List<string> { "Two" };
strings[1, 0] = new List<string> { "Three" };
strings[1, 1] = new List<string> { "Four" };
Run Code Online (Sandbox Code Playgroud)

  • 我弄明白了,这是IDE MonoDeveloper的错误,IDE无法识别这种情况,并给我一个错误的类型,真可惜.谢谢你的回答让我开始检查IDE (2认同)