Assuming you have a list of people with information such as name and nationality, stored in an array or a list. You can return ten person names from Spain using the following code:
main.cs452 chars18 lines
In this example, we use a foreach loop to iterate through the list of people and check if their nationality is Spain. If the person's nationality is Spain, we print their name to the console using Console.WriteLine(). We use a count variable to ensure that we only print 10 person names that have the nationality of Spain. Once the count reaches 10, we break out of the loop to stop the iteration.
gistlibby LogSnag