Say I have a constructor like this:
public MyClass(DateTime dateOfBirth, decimal cost)
{
DateOfBirth = dateOfBirth;
Cost = cost;
}
I need to add some validation. Do I need to check if these variables are null?
1) If I attempt to do this for cost, then there is a compiler warning saying that a decimal is never null:
if(cost==null) { }
2) If I attempt to do this for dateOfBirth, then there is no problem:
if(dateOfBirth==null) { }
3) If I attempt to do this for dateOfBirth, then there are two compiler errors (one for each variable):
MyClass mc = new MyClass(null, null);
Why is there no compiler error when I test for a DateTime null and a compiler error when I pass a null to a method that expects a DateTime? What validation do I need to do here for nulls?