I would like to add arrays to a list or multidimensional array (not all at once…). But I dont really understand why this should be that hard.
Lets say I have this:
string[] a = { "h", "b"};
string[] b = { "c", "a", "i" };
string[] c = { "out", "in", "file", "test" };
ArrayList x = null;
x.Add(a); //error: Object reference not set to an instance of an object.
x.Add(b);
x.Add(c);
Can I use instead of the ArrayList maybe
string[,] x = null;
But there is no option to .Add
Lets say I have an unknown amount of string[]´s with an unknown size – how do I add them to a List/multidimensional array? And again: I would like to add these string[]´s one by one. Any ideas?
You are getting an
NullReferenceExceptionbecause your list is not initialized:This assumes that you are constructing a 2-D structure. If you would like to “flatten” your arrays into a single list of strings, create a list, and use its
List.AddRangemethod instead.