I am trying to copy one jagged array into another jagged array with given offset. I came up with the following:
private void CopyWithOffset(char[][] buffer, (int row, int col) offset)
{
if (buffer == null) throw new ArgumentNullException(nameof(buffer));
for (var row = 0; row < buffer.Length; row++)
{
try
{
for (var col = 0; col < buffer[row].Length; col++)
{
try
{
_buffer[row + offset.row][col + offset.col] = buffer[row][col];
}
catch (IndexOutOfRangeException){}
}
} catch(IndexOutOfRangeException){}
}
}
Unfortunately it is very slow. Is there any way to do it faster?