Этот код должен работать.
String[,] leaguePairs = new String[3, 2] { { "Bayern Munich", "Bundesliga" }, { "Real Madrid", "La Liga" }, { "FC Barcelona", "La Liga" } };
String[,] playerPairs = new String[4, 2] { { "Player-1", "Bundesliga" }, { "Player-2", "La Liga" }, { "Player-3", "La Liga" }, { "Player-4", "*" } };
for (var i = 0; i < leaguePairs.GetLength(0); i++)
{
for (var j = 0; j < playerPairs.GetLength(0); j++)
{
if (Equals(playerPairs[j, 1], leaguePairs[i, 1]) || Equals(playerPairs[j, 1], "*"))
{
Console.WriteLine($@"[{playerPairs[j, 0]}, {leaguePairs[i, 0]}]");
}
}
}
Редактировать: (2018/5/9 9:58)
Вот метод, который вы хотите.
public String[,] MatchPlayers(String[,] leaguePairs, String[,] playerPairs)
{
var results = new List<(string, string)>();
for (var i = 0; i < leaguePairs.GetLength(0); i++)
{
for (var j = 0; j < playerPairs.GetLength(0); j++)
{
if (Equals(playerPairs[j, 1], leaguePairs[i, 1]) || Equals(playerPairs[j, 1], "*"))
{
results.Add((playerPairs[j, 0], leaguePairs[i, 0]);
}
}
}
var stringArray = new String[results.Count, 2];
for (var i = 0; i < results.Count; i++)
{
var result = results[i];
stringArray[i, 0] = result.Item1;
stringArray[i, 1] = result.Item2;
}
return stringArray;
}