Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

2-Dimension array of List in C#?

Tags:

arrays

c#

list

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.

like image 324
Matrix Bai Avatar asked Apr 08 '12 07:04

Matrix Bai


1 Answers

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" };
like image 171
Damir Arh Avatar answered Sep 23 '22 05:09

Damir Arh