Использование метода List.Contains

This commit is contained in:
Мельников Игорь 2022-12-06 21:21:18 +04:00
parent 8dd8105e4d
commit 86f03f05c5

View File

@ -28,13 +28,10 @@
/// <returns></returns> /// <returns></returns>
public int Insert(T locomotive) public int Insert(T locomotive)
{ {
for (int i = 0; i < _places.Count; i++) if (_places.Contains(locomotive))
{
if (locomotive.Equals(_places[i]))
{ {
throw new NotUniqueObjectException(); throw new NotUniqueObjectException();
} }
}
if (_places.Count == 0) if (_places.Count == 0)
{ {
_places.Add(locomotive); _places.Add(locomotive);