C# Do you need to check if something has a value and if something is greater than 0?
c#, if-statement
Solution
The code is probably redundant.
If i is `int?` then:
if (i.HasValue && i.Value > 0)
is equivalent to:
if (i > 0)
From MSDN:
When you perform comparisons with nullable types, if the value of one of the nullable types is null and the other is not, all comparisons evaluate to false except for != (not equal). It is important not to assume that because a particular comparison returns false, the opposite case returns true. In the following example, 10 is not greater than, less than, nor equal to null. Only num1 != num2 evaluates to true.
Problem
Working on a project and the coder does this a lot in his checks. First, he checks if the nullable `int` has a value, and then he checks if it's greater than 0. Why? Why make two checks if one check (if it is greater than 0) should be sufficient? Since nulls are not greater than 0, wouldn't that be redundant?