-3

Hello i have one class called Animal.cs and in my Program.cs i have created some animals..

class Program
    {
        static void Main(string[] args)
        {
            var AnimalList = new AnimslList();
        animalList.Add(new Animal{ Active = true, Name = "Bob", Photo = "Espanha" });
        animalList.Add(new Animal { Active = false, Name = "Robby", Photo = "Portugal" });
        animalList.Add(new Animal { Active = true, Name = "Snoop", Photo = "UK" });
        }
     }

and i have one class AnimalList.cs and in that class i added Animal list, and im getting the active animals with this code:

class AnimalList : List<Animal>
{
    public List<Animal> GetActiveAnimals()
    {
        return this.FindAll(p => p.Active);
    }
}

and my problem is in this class he called Event.cs in event.cs i want get the results from GetActiveAnimals() because i just want to get the active animals for the event can someone help me please?

class Event
    {
        private AnimalList _contestants;
    }

i should get the Active from the AnimaList in this one above. The active ones should go into _contestants

1 Answers1

2

Extend your Event by a constructor for example

class Event
{
    private AnimalList _contestants;
    public Event(AnimalList contestants)
    { 
         _contestants = contestants;
    }
}

and then forward the list when you create an event:

static void Main(string[] args)
{
    var AnimalList = new AnimslList();
    animalList.Add(new Animal{ Active = true, Name = "Bob", Photo = "Espanha" });
    animalList.Add(new Animal { Active = false, Name = "Robby", Photo = "Portugal" });
    animalList.Add(new Animal { Active = true, Name = "Snoop", Photo = "UK" });
    var event = new Event(AnimalList.GetActiveAnimals();
}
AlfredJK
  • 46
  • 4