public static void Main()
int[,] data = new int[4,4] { {1,2,3,4}, {5,6,7,8}, {9,1,2,3}, {4,5,6,7} };
Console.WriteLine("Initial: ");
var result = RemoveBorders(data);
Console.WriteLine("\nResult: ");
public static void Print2DArray<T>(T[,] data)
for(int i = 0; i<=data.GetUpperBound(0);i++)
for (int j = 0; j<=data.GetUpperBound(1);j++)
Console.Write(data[i,j]);
public static T[,] RemoveBorders<T>(T[,] source)
var ROW = source.GetUpperBound(0);
if (ROW < 2) throw new ArgumentException("source array is not tall enough");
var COL = source.GetUpperBound(1);
if (COL < 2) throw new ArgumentException("source array is not wide enough");
var result = new T[ROW - 1, COL - 1];
for (int r = 1; r < ROW; r++)
for (int c = 1; c < COL; c++)
result[r-1, c-1] = source[r, c];