- Lambda expressions and anonymous methods replace the specified single-use delegate handlers.
Then remove the HandleBalanceChanged method.
Anonymous Methodsthis.moneyPocket.OnBalanceChange = () =>
{
this.OnBalanceChange?.Invoke();
};Then remove the HandleBirthingRoomTemperatureChange method.
The previousTemp and currentTemp mean that those are the two parameters needed. The types of these parameters are assumed.
this.b168.OnTemperatureChange = (previousTemp, currentTemp) =>
{
// HandleBirthingRoomTemperatureChange code goes here
};Then remove the Update method.
this.cage.OnImageUpdate = item =>
{
// code here
};Then remove the unused methods.

It will be used to alert the zoo when an animal becomes pregnant.
The anonymous method adds that animal to the birthing room's queue.
animal.OnPregnant = pregnantAnimal => this.b168.PregnantAnimals.Enqueue(pregnantAnimal);animal.OnPregnant = (pregnantAnimal) =>
{
this.b168.PregnantAnimals.Enqueue(pregnantAnimal);
};Handle animals that have been added through a list initializer by plugging the same code/anonymous method in to each animal's pregnancy delegate in the zoo's OnDeserialized method (within the foreach loop).
Run the WPF application.
Then edit the animal and make it pregnant. The breakpoint should be hit, which means that the method was attached to the delegate correctly.
The pregnant animal should give birth to a baby animal and become not pregnant. The baby animal should be added to the list box.
In this task, you will replace existing simple foreach loops (ones containing only a single line of code in the loop) with calls to the ForEach and ToList extension methods and lambda expressions. You will check your work by ensuring that the functionality of the WPF and console applications remain the same as before refactoring the loops.
The ForEach method is only available on lists, so you will have to call the ToList method before calling the ForEach method.
list.ToList().ForEach(s => result += result == null ? s : separator + s);Increment the zIndex variable when passing it in to the DrawItem method instead of after calling the method.
c => this.DrawItem(c, zIndex++)this.guests.ForEach(g =>
{
this.OnAddGuest(g);
g.GetVendingMachine += this.ProvideVendingMachine;
});Since this foreach loop has more than one line of code in it, we need to add curly braces to signify that the code applies to all objects. Structure:
ForEach(param => { //code here });Open their cage. All animals should still be drawn correctly, and they should not flip back and forth between the background and foreground.
Create two guests. Stop and restart the application. The guests should be deserialized successfully and should appear in the list box.
The information, including the usage and parameter details, should be written to the console as they were before the change.
In this task, you will practice using lambda expressions and extension methods built into the .NET framework by writing queries to find specific animals and guests and finding information about all animals in the zoo. You will check your work by running the queries and ensuring that you get the correct result.
6.4.5 How to Write and Use LINQ Queries
Inside the case statement, assign a local string variable to a call to the QueryHelper method. Pass in the zoo and the second command in the commandWords array.
Then add a switch statement that switches on the query parameter.
Do not use the TotalAnimalWeight property.
result = zoo.Animals.ToList().Sum(a => a.Weight).ToString();Do not use the AverageAnimalWeight property.
Do not use the AnimalCount property.
Then, use the FindAnimal method to find the first animal whose weight is over 200 pounds and add that animal to the list. Then, use the ForEach extension method to set the resulting animal the local string variable.
Then find the first guest who is 10 years old or younger and add that guest to the list. Use the ForEach extension method to set the resulting guest to the local string variable.
Then find the first animal who is both a dingo and is female and add that animal to the list. Use the ForEach extension method to set the resulting animal the local string variable.
A representation of an ostrich named Stretch should appear in the data grid.
A representation of Darla who is under 10 should appear in the data grid.
A representation of the dingo named Maggie should appear in the data grid.
© 2026 Northcentral Technical College