I can move element "kanin" from dimension 0 to 1, but not back with my else statment. My goal is to check if this "element" is in dimension 0, it moves to dimension 1, and if it is in dimension 1 it moves to dimension 0. But only the if-statement works
public static string[,] Kanin(string[,] strand) {
for (int i = 0; i < strand.GetLength(0); i++)
{
if (i==0)
{
for (int x = 0; x < strand.GetLength(1); x++)
{
if (strand[i, x] == "kanin")
{
for (int y = 0; y < strand.GetLength(1); y++)
{
if (strand[1, y] == "")
{
strand[1, y] = strand[i, x];
strand[i, x] = "";
}
}
}
}
}
else
{
for (int x = 0; x < strand.GetLength(0); x++)
{
if (strand[i, x] == "kanin")
{
for (int y = 0; y < strand.GetLength(0); y++)
{
if (strand[0, y] == "")
{
strand[0, y] = strand[i, x];
strand[i, x] = "";
}
}
}
}
}
}
return (strand);
}
Aucun commentaire:
Enregistrer un commentaire