# Matrix Operations Versión en español de esta publicación.
Some time ago I was presented with some algorithms common problems related to matrices, today I just found some code in my Windows virtual machine and I through that maybe it was a good idea to publish it here just to keep it online.

I remember I was looking for an algorithm to print a square matrix in spiral, and I found some code in the internet as usual which used a nice approach, I had to modify it because it was in another language and I needed it to be in C#,

Well here is the class I made with the internet approach, the class supports square matrix multiplication and also supports printing a square matrix in spiral using an indirect recursive approach.

Matrices.cs

```﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace Samples
{
public static class Matrices
{
public static double[,] MtxMult(double[,] mtxA, double[,] mtxB)
{
if (mtxA == null || mtxA.Length == 0)
throw new ArgumentException(&quot;Array parameter must be valid&quot;);

if (mtxB == null || mtxB.Length == 0)
throw new ArgumentException(&quot;Array parameter must be valid&quot;);

if (mtxA.Length != mtxB.Length)
throw new ArgumentException(&quot;Arrays must have the same length&quot;);

int size = mtxA.GetLength(0); // get first dimmension lenght
double[,] mtxC = new double[size, size];
for (int i = 0; i &lt; size; i++)
for (int j = 0; j &lt; size; j++)
{
// Compute dot product of row i and column j.
for (int k = 0; k &lt; size; k++)
mtxC[i, j] += mtxA[i, k] * mtxB[k, j];
}

return mtxC;
}

private static IList&lt;int&gt; _spiralMtx = null;
public static IList&lt;int&gt; MtxProcessSpiral(int[,] mtx)
{
_spiralMtx = null;
_spiralMtx = new List&lt;int&gt;();
int x1 = 0;
int y1 = 0;
int x2 = mtx.GetLength(0) - 1;
int y2 = mtx.GetLength(1) - 1;
MtxProcessTopRight(mtx, x1, y1, x2, y2);
return _spiralMtx;
}

//
// prints the top and right shells of the matrix
//
private static void MtxProcessTopRight(int[,] mtx, int x1, int y1, int x2, int y2)
{
int i = 0;
int j = 0;
// print the row
for (i = x1; i &lt;= x2; i++)

//print the column
for (j = y1 + 1; j &lt;= y2; j++)

// see if we have more cells left
if (x2 - x1 &gt; 0 &amp;&amp; y2 - y1 &gt; 0)
{
// 'recursively' call the function to print the bottom-left layer
MtxProcessBottomLeft(mtx, x1, y1 + 1, x2 - 1, y2);
}
}

//
// prints the bottom and left shells of the matrix
//
private static void MtxProcessBottomLeft(int[,] mtx, int x1, int y1, int x2, int y2)
{
int i = 0;
int j = 0;
// print the row of the matrix in reverse
for (i = x2; i &gt;= x1; i--)

// print the last column of the matrix in reverse
for (j = y2 - 1; j &gt;= y1; j--)