Iterating over collections
To start exploring collections, let’s go back to the BoardingProcessor class and look at its DisplayPassengerBoardingStatus method. We’ll explore this method a bit at a time, starting with its method signature:
public void DisplayBoardingStatus(
List<Passenger> passengers, bool? hasBoarded = null) {
Here, we can see that the method takes in a list of Passenger objects and, optionally, a nullable boolean hasBoarded parameter that can store true, false, or null. This hasBoarded parameter is used to optionally filter down our list of passengers based on its value:
true: Only include passengers who have boarded the planefalse: Only include passengers who have not yet boardednull: Do not filter by boarded status (default option)
This nullable filtering parameter is a common one I see while building search methods and we’ll explore it in more depth again in Chapter 5, Object-oriented Refactoring...