public void spiral(int[, ] arr)
int right = arr.GetLength(1) - 1;
int bottom = arr.GetLength(0) - 1;
for (int i = left; i <= right; i++)
Console.Write("{0},", arr[top, i]);
for (int i = top; i <= bottom; i++)
Console.Write("{0},", arr[i, right]);
for (int i = right; i >= left; i--)
Console.Write("{0},", arr[bottom, i]);
for (int i = bottom; i >= top; i--)
Console.Write("{0},", arr[i, left]);
public static void Main()
int[, ] arr2d = new int[, ]{{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}};
Program p = new Program();