to be able to use an object in a method it has to be instantiated first!
Your array jdata
has the value null
so you cannot access it.
Initialize it first and give it the proper dimensions, so that it is clear how much memory has to be acquired in advance:
public static string[,] jdata = new string[names.Length, 1];
Also if you want to use your while-loop as it is you need to start with i
at -1. Otherwise you will skip the first entry. And you should only run until names.Length-1
while (i++ < names.Length-1)
{
jdata[i, 0] = names[i];
}
Why not using a classic for-loop? It does not byte:
for (int i = 0; i < names.Length; i++)
{
jdata[i, 0] = names[i];
}
Am I able to change the size later? Meaning: changing value 1 to another size?
If you want to do that I would suggest to use a List. The Add
method allows you to extend the size of the List. In this example it is a List of Lists, which you can imagine as a table with columns and rows. Only the not all columns have necessarily the same amount of rows.
static void Main(string[] args)
{
List<string> names = new List<string> { "cmd", "EUI", "ts", "fcnt", "port", "freq", "dr", "ack", "gws", "data" };
List<List<string>> jdata = new List<System.Collections.Generic.List<string>>
jdata.Add(names);
Console.ReadKey();
}
This has 2 Advantages:
1) The lists that you save in your columns can have different lengths
2) you can remove and add values as you please
To access the first column you can just use the [ ]
operator:
List<string> savednames = jdata[0];