find the position surrounded by the opposite no in a 2d array code example

Example: find the position surrounded by the opposite no in a 2d array

int[] rowNbr = { -1, -1, -1, 0, 0, 1, 1, 1 };
            int[] colNbr = { -1, 0, 1, -1, 1, -1, 0, 1 };
            for (int x = 0; x < 8; x++)
            {
                int facX = rowNbr[x];
                int facY = colNbr[x];
                try
                {
                    for (int i = 1; i < length; i++)
                    {
                        if (pieces[click.X + i * facX, click.Y + i * facY] == 0) break;
                        if (pieces[click.X + i * facX, click.Y + i * facY] == (byte)num)
                        {
                            for (int j = i - 1; j > 0; j--)
                            {
                                pieces[click.X + j * facX, click.Y + j * facY] = (byte)num;
                            }
                            break;
                        }
                    }
                }
                catch { } 
            }