Search code examples
c#nullzerodead-code

Why is setting an int to 0 considered moot after a null check?


I've got this code setting an int val to 0 if it is null:

if (null == frbdcbl.QtyOrdered)
{
    frbdcbl.QtyOrdered = 0;
}

...but the assignment is greyed out, as if such an operation is moot. Why would that be? After all, null != 0.

The value being checked does not have a default value of 0 or such:

public class FillRateByDCByLocation
{
    . . .
    public int QtyOrdered { get; set; }
}

The code with the grayed out assignment (AddFillRateByDCByLocationRow(()) is called like so:

foreach (FillRateByDCByLocation frbdcbl in _fillRateByDCByLocGroupedSortedSummed)
{
    AddFillRateByDCByLocationRow(frbdcbl);
}

Solution

  • Is it a nullable int? If not, its grayed out because int's can never be null.