Finding all neighbors of any given element in a matrix like structure
You could use a 2-dimensional loop to iterate over neighbors as follows:

public IEnumerable&lt;Coordinates&gt; GetNeighbors(int numberOfRows, int numberOfColumns)
{
    var canIncreaseRow = Row &lt; numberOfRows - 1;
    var canIncreaseColumn = Column &lt; numberOfColumns - 1;
    var canDecreaseRow = Row &gt; 0;
    var canDecreaseColumn = Column &gt; 0;

    var maxRow = canIncreaseRow ? Row + 1 : Row;
    var minRow = canDecreaseRow ? Row - 1 : Row;
    var maxColumn = canIncreaseColumn ? Column + 1 : Column;
    var minColumn = canDecreaseColumn ? Column - 1 : Column;

    for (int row = minRow; row &lt;= maxRow; row++)
    {
        for (int column = minColumn; column &lt;= maxColumn; column++)
        {
            if (row != Row || column != Column)
            {
                yield return new Coordinates(row, column);
            }
        }
    }
}