   [.net] C# multidimensional array of List?
  Maybe something else would be simpler but I need something like this:So on a each coordinate on a map 1000 x 1000 to be able to have 0 or 1000 elements?I want to be able to do something like myMap[120,15].Add("tree")   
Quote:Original post by davidcolemanMaybe something else would be simpler but I need something like this:So on a each coordinate on a map 1000 x 1000 to be able to have 0 or 1000 elements?I want to be able to do something like myMap[120,15].Add("tree")Something like this?System.Collections.Generic.List<string>[,] myMap = new System.Collections.Generic.List<string>[1000, 1000];myMap[120,15].Add("tree");;  I get this message  System.Collections.Generic.List<string>[] myMap = new System.Collections.Generic.List<string>[1000];for (int i = 0; i < 1000; i++) myMap.Add("tree");NullReferenceException was unhandled   ;  For reference types, you still need to new individual elements of an array before using them. It should look something like:System.Collections.Generic.List<string>[] myMap = new System.Collections.Generic.List<string>[1000];for (int i = 0; i < 1000; i++) {  myMap = new System.Collections.Generic.List<string>();  myMap.Add("tree");};  Thanks! This solved the problem!   