private void btnCalculate_Click(object sender, EventArgs e) { foreach (var animal in _animals) { if (!_train.GetWagon().Any()) { CreateWagon(animal); continue; } var canEnter = false; foreach (var wagon in _train.GetWagon()) { canEnter = wagon.CheckRules(animal); if (canEnter) { wagon.AddAnimal(animal); listBox2.Items.Add(wagon.ToString()); break; } } if (!canEnter) { CreateWagon(animal); } } listBox2.DataSource = _train.GetWagon(); }