The problem is that your AnimalList in your Main method:
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" });
}
Is local to the function - you can't access it outside the function unless you pass it to another method.
So if you were to do this:
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" });
Event ev = new Event();
ev.ListOfAnimalsPropertyYouNeedToAdd = AnimalList;
...
}
You can then use the list you passed in to identify the active ones:
foreach (Animal a in ev.GetActiveAnimals())
{
...
}
By writing the code in your Event class:
public List<Animal> GetActiveAnimals()
{
return ListOfAnimalsYouSavedWhenYouSetThePropertyEarlier.GetActiveAnimals();
}
(But don't call it
Event
- that has a specific meaning in C# that your teacher will explain later)