The ?. Operator in foreach Will Not Protect From NullReferenceException

Do you like the ?. operator? Well, who doesn't? Many people like these concise null checks. However, today's article shows that the ?. operator may be tricky sometimes. That is, it can create an illusion of safety when used in the foreach loop.

Let's start with a small task. Take a look at the following code: