从DateTime返回时出错

sla*_*dau 0 .net c# datetime

int monthCount = GetMonthCount(comp.PaymentFrequency);
int day = comp.MaturityDate.GetValueOrDefault(DateTime.Today).Day;
DateTime countFrom = comp.EffectiveDate.GetValueOrDefault(DateTime.Today);

return new DateTime(countFrom.Year, countFrom.Month, day).AddMonths(monthCount);
Run Code Online (Sandbox Code Playgroud)

年,月和日参数描述了无法代表的日期时间?为什么?

SLa*_*aks 5

如果MaturityDate是1/31/2011和EffectiveDate 2/28/2011,您的代码将尝试创建一个不存在的日期.