public static void Swap(ref int a, ref int b)
public static void Sort(int [,] mt)
int rows = mt.GetLength(0);
int cols = mt.GetLength(1);
for (int i = 0; i < n-1; i++)
for (int j = i+1; j < n; j++)
if (mt[i/cols,i%cols] > mt[j/cols,j%cols])
Swap(ref mt[i / cols, i % cols],ref mt[j / cols, j % cols]);
public static void Sort1(int[,] mt)
int rows = mt.GetLength(0);
int cols = mt.GetLength(1);
for (int i = 0; i < rows; i++)
for (int j = 0; j < cols; j++)
for (int r = i; r < rows; r++)
for (int c = i==r? j+1:0; c < cols; c++)
Swap(ref mt[i, j], ref mt[r, c]);
public static void Main()
int[,] mt = { { -1, 2, 3 },