Replace a Set of Choices with FirstOrDefault
Use the FirstOrDefault method to replace a chain of conditionals.
We'll cover the following...
We'll cover the following...
How to Refactor a chain of conditionals with FirstOrDefault
When we need to find a value between multiple choices, we write consecutive if statements to check for a valid result every time.
For example, let’s find the next film to watch from one of three sources: the latest releases in cinemas, our friends’ recommendations, and the all-time classics.
Notice that after we called a ...