diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs index 62658b2..651cabd 100644 --- a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs +++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs @@ -145,8 +145,7 @@ namespace ElectricLocomotive int pos = Convert.ToInt32(Input.Text); try { - var removeObj = obj - pos; - if (removeObj != null) + if ( obj - pos != null ) { MessageBox.Show("Объект удален"); _logger.LogInformation($"Удален объект с позиции{pos}"); @@ -155,6 +154,7 @@ namespace ElectricLocomotive else { MessageBox.Show("Не удалось удалить объект"); + _logger.LogWarning($"Не удалось удалить объект из набора {listBoxStorage.SelectedItem.ToString()}"); } } catch (LocoNotFoundException ex) diff --git a/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs b/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs index 92bc661..c7d91a1 100644 --- a/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs +++ b/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs @@ -36,16 +36,14 @@ namespace ProjectElectricLocomotive.Generics _places.Insert(position, loco); return position; } - public T? Remove(int position) + public bool Remove(int position) { - if (position >= Count || position < 0) - return null; - - T? tmp = _places[position]; - if (tmp == null) + if (position < 0 || position >= _places.Count) + { throw new LocoNotFoundException(position); - _places[position] = null; - return tmp; + } + _places.RemoveAt(position); + return true; } public T? this[int position] {