乔恩感谢,你是绝对正确的,让我装上缺少的next()方法是在类中:
public date Next(date d)
{
if (!d.valid()) return new date();
date ndat = new date((d.Day() + 1), d.Month(), d.Year());
if (ndat.valid()) return ndat;
ndat = new date(1, (d.Month() + 1), d.Year());
if (ndat.valid()) return ndat;
ndat = new date(1, 1, (d.Year() + 1));
return ndat;
}
由于该使用有效()我也重视这一点:
public bool valid()
{
// This method will check the given date is valid or not.
// If the date is not valid then it will return the value false.
if (year < 0) return false;
if (month > 12 || month < 1) return false;
if (day > 31 || day < 1) return false;
if ((day == 31 && (month == 2 || month == 4 || month == 6 || month == 9 || month == 11)))
return false;
if (day == 30 && month == 2) return false;
if (day == 29 && month == 2 && (year % 4) != 0) return false;
if (day == 29 && month == 2 && (((year % 100) == 0) && ((year % 400) != 0))) return false;
/* ASIDE. The duration of a solar year is slightly less than 365.25 days. Therefore,
years that are evenly divisible by 100 are NOT leap years, unless they are also
evenly divisible by 400, in which case they are leap years. */
return true;
}
Day(),Month()和Year()我认为是自我解释,但让我知道他们是否需要。我也有一个previous()方法,它与next()方法相反,我想在 - decrement方法中使用它。
现在在我的计划,我有
class Program
{
static void Main()
{
date today = new date(7,10,1985);
date tomoz = new date();
tomorrow = today++;
tomorrow.Print(); // prints "7/10/1985" i.e. doesn't increment
Console.Read();
}
}
所以它实际上并没有失败,只是打印当天的日期,而不是明天的,但正常工作,如果我用了++今天来代替。
关于D/M/Y的顺序,是的,我同意,更高的频率数据我可以看到这是如何改善的东西,接下来我将着手解决这个问题。
呃,当然是吗?你明天将分配给今天的价值然后增加它。 – 2009-12-24 12:06:22
你不会期望明天在2之后:'int today = 1; int明天=今天++;' – 2009-12-24 12:08:54
啊坚果你是对的!谢谢Garry – Victor 2009-12-24 12:13:17