how return array name in array

Hi all, I have an array of arrays - I believe it’s called jagged array, but I’m not sure. How can I access or return the NAMES of arrays within that array? Not the values. I would like to print out the array names.

string[] groupA = new string[]{name1, name2, name3, name4, name5};
string[] groupB = new string[]{name6, name7, name8, name9, name10};
string[] groupC = new string[]{name11, name12, name13, name14, name15}; 
string[] groupD = new string[]{name16, name17, name18, name19, name20};
string[] groupE = new string[]{name21, name22, name23, name24, name25};

strging[][] groups = new string[][]{groupA, groupB, groupC, groupD, groupE};

I would like to get for example the third item in groups array by name:
So that when I do this:


I would like the program to print out “group C”. Not the items in group C.

I would look to use List or Dictionary. One suggestion:

List<KeyValuePair<string, string[]>> groups = new List<KeyValuePair<string, string[]>>();
groups.Add(new KeyValuePair<string, string[]>("Group A", new string[]{name1, name2, name3, name4, name5});
groups.Add(new KeyValuePair<string, string[]>("Group B", new string[]{name6, name7, name8, name9, name10});
groups.Add(new KeyValuePair<string, string[]>("Group C", new string[]{name11, name12, name13, name14, name15});

If you would like to print the group name now, you can do:


If you want to access a group you can do:


If you would like to access a name in a group:


First of all, i would like to tell you that this way of using arrays is extremly ineffective.
i have to agree with Unitraxx that his solution is a better one.

but if you wanna do it realy with our static sourcecode a solution would be the following.

Just add another array to your sourcecode

string[] groupNames = { "groupA", "groupB", "groupC", "groupD", "groupE"};

with this help array, you can use the index for grabbing the array from the toparray and gather informations, or you are using the index on the groupNames array to get the name of the array you defined.


int indexValue = 2;
int groupId = 1;
string groupAValue = groups[groupId][indexValue];
string groupName = groupNames[groupId];

Debug.Log("Groupname:"+groupName+" / Value:"+groupAValue);

the result would be “Groupname:groupA / Value:a Value”

but i realy want to mention again, you should change soon to the keypair value solution.