LeetCode: Transpose Matrix C#
You iterate through the same array twice (once while initializing and once while assigning values), you can do both inside the same loop.

for (int i = 0; i &lt; w; i++)
{
    res[i] = new int[h];
    for (int j = 0; j &lt; h; j++)
    {
        res[i][j] = A[j][i];
    }
}