Поменять местами строки в двумерном массиве - C#
Формулировка задачи:
}
static void SortLine(int[,] linemas)
{
for (int i = 1; i < linemas.GetLength(0); i++)
{
for (int j = 0; j < linemas.GetLength(1); j++)
{
int buf = linemas[i - 1, j];
linemas[i -1, j] = linemas[i, j];
linemas[i, j] = buf;
}
}
}Решение задачи: «Поменять местами строки в двумерном массиве»
textual
Листинг программы
static void ReplaceRows(int[,] matr, int rowIndex1, int rowIndex2)
{
if (rowIndex1 < 0 || rowIndex1 >= matr.GetLength(0) || rowIndex2 < 0 || rowIndex2 >= matr.GetLength(0) || rowIndex1 == rowIndex2)
return;
for (int i = 0; i < matr.GetLength(1); i++)
{
int buf = matr[rowIndex1, i];
matr[rowIndex1, i] = matr[rowIndex2, i];
matr[rowIndex2, i] = buf;
}
}