public static void ReplaceListener(UpdateListener listener, SudokuGrid value, ref SudokuGrid grid) { if (grid == value) { return; } if (grid != null) { grid.RemoveListener(listener); } grid = value; if (grid != null) { grid.AddListener(listener); } }