```
public void Rotate(int[,] matrix)
{
int n = matrix.GetLength(0);
int a = 0;
int b = n - 1;
while (b > a)
{
for (int i = a; i < b; i++)
{
int tmp = matrix[a, i];
matrix[a, i] = matrix[a + b - i, a];
matrix[a + b - i, a] = matrix[b, a + b - i];
matrix[b, a + b - i] = matrix[i, b];
matrix[i, b] = tmp;
}
a++;
b--;
}
}
```