I've been looking through some MS reference material for an upcoming exam and have found a supposedly previous question where I disagree with the answer.
Upon consideration, I'm going to post a screenshot of the question rather than condense the problem just in case I abstract out any pertinent information to the question at hand.
The issue I have is that they give the answer as B whereas I think it should be A for the following reasons.
The where clause in the LINQ query has two criteria it has to compare against one where the Years match in the DateTime? object and the method parameter.
However, I'm more interested in why they think a null check is necessary due to the parameter type being a non-nullable int. Unassignment and attempting to assign null prior to passing the parameter by value will result in a compiler error.
If the year param can never be null, there will never be a null DateTime match - rendering the null check superfluous.
I can see why B would also yield expected results, but is there anything wrong with answering A.
(P.s. I've read - Comparing non nullable `int` to `null` (LINQ) which seems to back up my theory, I'm just squeamish about disagreeing with reference material)