you can't use
Array.Resize<string[,]>(ref array1, array1.Length + array2.Length);
since the elements in your array are not of type string[,]. It would work if you had a string[][] because then you could use
Array.Resize<string[]>(....);
For multidimensional arrays there is afaik no built-in method so you have to do it simply "manually"
public static string[,] CombineArrayFunction(string[,] array1, string[,] array2)
{
var finalArray = new string[array1.Length + array2.Length, 2];
// simply first run through the one array
for (var i = 0; i < array1.Length; i++)
{
finalArray[i, 0] = array1[i, 0];
finalArray[i, 1] = array1[i, 1];
}
// then run through the second array
for (var i = 0; i < array2.Length; i++)
{
// simply add an offset to the index
// according to the length of the first array
finalArray[i + array1.Length - 1, 0] = array2[i, 0];
finalArray[i + array1.Length - 1, 1] = array2[i, 1];
}
return finalArray;
}
However maybe the main issue is in your data structure itself.
A Dictionary as mentioned by Rawitas Krungkaew might be a better approach in the case you have unique keys because then it is also faster in access if you later are looking for a specific value.
If your use case is rather only about storing and e.g. displaying this information somewhere I would actually recommend to rather use a proper custom type and a simple flat list like e.g.
public List<ScoreEntry> scoreBoard = new List<ScoreEntry>();
[Serializable]
public class ScoreEntry
{
public string Name;
// or still string if you want to stick to that
public int Score;
public ScoreEntry(string name, int score)
{
Name = name;
Score = score;
}
}
then you could simply either add an item
scoreBoard.Add(new ScoreEntry("Bob", 100))
or if needed multiple ones using AddRange
scoreBoard.AddRange(new List<ScoreEntry>{new ScoreEntry("Bob", 100), new ScoreEntry("Marley", 200)});
There are a lot more advantages of this list.
For example it can be very simply iterated without having to care about two indices all the time.
And in particular for having a score board since you can now use all the magic from Linq (using Syste.Linq;) and filter and sort your list.
e.g. sort this list alphabetic
var alphabeticallyOrdererList = scoreBoard.OrderBy(e => e.Name).ToList();
or by score
var scoreOrderedList = scoreBoard.OrderByDescending(e => e.Score).ToList();
or use both to first order by score and if equal order by name
var scoreAndAlphabeticallyOrderedList = scoreBoard.OrderByDescending(e => e.Score).ThenBy(e => e.Name).ToList();
or return all entries belonging to "Bob"
var bobEntries = scoreBoard.Where(e => string.Equals(e.Name, "Bob")).ToList();
And if you then still need to access a certain entry Linq offers a lot of magic. For example find the maximum score for "Bob"
var entry = scoreBoard.Where(e => string.Equals(e.Name, "Bob")).OrderByDescending(e => e.Score).FirstOrDefault();
either returns the highest score of "Bob" or 0 if there was none in the list.
Another advantage of this list is that it is directly serializable so 1. You can actually see it in the Unity Inspector. It is saved if you e.g. fill it with some default values in the Inspector.
You can also directly serilaize and deserialize it to the most formats like XML, JSON (for those you need a wrapper class for the list) or simply in a textfile with one line per entry etc