title: Swapping the data in the submatrix efficiently
body: <p>I need to swap the data in the matrix using C#. You can imagine this swap as it is like in the matrix transposition. </p>
  
  <pre><code>| a11 a21 |   ---&gt;  | a11 a12 |
  | a12 a22 |         | a21 a22 |
  </code></pre>
  
  <p>I have written this code for this purpose;</p>
  
  <pre><code>  public void SwapSubMatrix(int xStart, int yStart, int size)
    {
  
         for (int i = xStart; i &lt; xStart + size; i++)
         {
              for (int j = yStart; j &lt; yStart + size; j++)
              {
  
                    this.temp = this.matrix[i, j];
                    this.matrix[i, j] = this.matrix[i - size, j + size];
                    this.matrix[i - size, j + size] = this.temp;
              }
         }
     }
  </code></pre>
  
  <p>Basically, I am passing the <code>a21's column and row position and the size of the it</code>, then it changes the values between <code>a21</code> and <code>a12</code></p>
  
  <p>It completely works, but I'm wondering is there another way to do it fast. Because in my situation even milliseconds are so important. If is there another way that uses caches efficiently or a helper function to do this (like memcpy or sth like it in the C) , I would like to know.</p>