示例#1
0
            public T Remove(T animal)
            {
                var element = ListOfAnimals.FirstOrDefault(h => h == animal);

                if (element != null)
                {
                    ListOfAnimals.Remove(element);
                    return(element);
                }
                throw new NullReferenceException("В экземпляре объекта не задана ссылка на объект!");
            }
示例#2
0
        public void SlaughterAnimal()
        {
            Animal target = null;

            foreach (var animal in ListOfAnimals)
            {
                if (target == null || animal.Hunger < target.Hunger)
                {
                    target = animal;
                }
            }
            ListOfAnimals.Remove(target);
        }
示例#3
0
        public void SlaughterOne()
        {
            int hunger = 50;
            int index  = 0;

            for (int i = 0; i < ListOfAnimals.Count; i++)
            {
                if (ListOfAnimals[i].Hunger <= hunger)
                {
                    hunger = ListOfAnimals[i].Hunger;
                    index  = i;
                }
            }
            ListOfAnimals.Remove(ListOfAnimals[index]);
        }
示例#4
0
        public void SlaughterLinq()
        {
            var hungryAnimal = ListOfAnimals.OrderByDescending(a => a.Hunger).First();

            ListOfAnimals.Remove(hungryAnimal);
        }