public static void Main()
Console.WriteLine(traverse(new [] {1, 2, 3, 4, 5, 10, 15, 20, 25, 24, 23, 22, 21, 16, 11, 6, 7, 8, 9, 14, 19, 18, 17, 12, 13}, 5, 5));
static int getIndex(int x, int y, int colums)
static String traverse(int[] matrix, int rows, int columns)
int colLength = columns-1;
while(rowStart <= rowLength && colStart <= colLength)
for (int i = rowStart; i <= colLength; i++)
output += matrix[getIndex(rowStart, i, columns)] + ", ";
for (int j = rowStart+1; j <= rowLength; j++)
output += matrix[getIndex(j, colLength, columns)] + ", ";
if(rowStart+1 <= rowLength)
for (int k = colLength-1; k >= colStart; k--)
output += matrix[getIndex(rowLength, k, columns)] + ", ";
if(colStart+1 <= colLength)
for (int k = rowLength-1; k > rowStart; k--)
output += matrix[getIndex(k, colStart, columns)] + ", ";
return output.Substring(0, output.Length - 2);