public static void UpdatePregnancy() { AnimalUtility .FindAnimals(a => a.GetDaysUntilBirth().HasValue) .ToList() .ForEach(a => a.SetDaysUntilBirth(a.GetDaysUntilBirth().Value - 1)); }
public static Character ContestParticipant(SDate contestDate) { Pet pet = Game1.player.getPet(); return(pet.GetDayParticipatedContest() == contestDate ? (Character)pet : AnimalUtility.FindAnimals(a => a.GetDayParticipatedContest() == contestDate).FirstOrDefault()); }
public static IEnumerable <FarmAnimal> AnimalsReadyForBirthTomorrow() { return(AnimalUtility.FindAnimals( a => { int?daysUntilBirth = a.GetDaysUntilBirth(); return daysUntilBirth.HasValue && daysUntilBirth.Value == 1; } )); }
static void Main(string[] args) { //Create our animal objects but only talk to them by the interface (contract) they signed IAnimal eagle = new Eagle(); IAnimal chicken = new Chicken(); IAnimal bear = new Bear(); //Add our animals to an array the only cares about the interface they implement (the contract or the what) not the //classes that are really implementing the code inside (the how) IAnimal[] animals = new IAnimal[] { eagle, chicken, bear }; //Call the static DoSomething method on AnimalUtility passing in each animal foreach (var animal in animals) { AnimalUtility.DoSomething(animal); } Console.ReadLine(); }