Dimension array of List in C#?

I just want get a 2 dimension array of List in c#. In my thought, below should works but it didn't, the 1 dimension array of List works. I use Unity3D with Mono, however I think it's language related problem.

List<MyType>[,] twoDArrayofList;//don't work, it's type is List<MyType>
List<MyType>[] oneDArrayofList;//it's works, the type is List<MyType>

Anyone know what's wrong? Thank you.


What do you mean by "doesn't work"? What error are you getting?

I don't know about Mono (or Unity3D), but I just tried the following in a .NET project and got the results I expected:

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" };

This is an older post, but it came up in my search for a similar answer. I found that creating a Dictionary instead of a List meets my needs. You can't iterate by index, but if you have a discrete list and you are iterating through the first string "Key", you can easily obtain the second string "Value".

Here is a stackoverflow post with examples: What is the best way to iterate over a Dictionary in C#?

链接地址: http://www.djcxy.com/p/30398.html

上一篇: 如何迭代一个`IDictionary`的键和值?

下一篇: 在C#中的列表维度数组?