本文整理汇总了C#中Date.AddYears方法的典型用法代码示例。如果您正苦于以下问题:C# Date.AddYears方法的具体用法?C# Date.AddYears怎么用?C# Date.AddYears使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Date
的用法示例。
在下文中一共展示了Date.AddYears方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanAddPositiveYears_FromLeapDay_ToLeapYear
public void CanAddPositiveYears_FromLeapDay_ToLeapYear()
{
var dt = new Date(2000, 2, 29);
var actual = dt.AddYears(4);
var expected = new Date(2004, 2, 29);
Assert.Equal(expected, actual);
}
示例2: CanAddNegativeYears_FromLeapDay_ToNonLeapYear
public void CanAddNegativeYears_FromLeapDay_ToNonLeapYear()
{
var dt = new Date(2000, 2, 29);
var actual = dt.AddYears(-1);
var expected = new Date(1999, 2, 28);
Assert.Equal(expected, actual);
}
示例3: CanAddNegativeYears
public void CanAddNegativeYears()
{
var dt = new Date(2000, 1, 1);
var actual = dt.AddYears(-1);
var expected = new Date(1999, 1, 1);
Assert.Equal(expected, actual);
}
示例4: CanAddZeroYears
public void CanAddZeroYears()
{
var dt = new Date(2000, 1, 1);
var actual = dt.AddYears(0);
var expected = new Date(2000, 1, 1);
Assert.Equal(expected, actual);
}
示例5: CanAddPositiveYears
public void CanAddPositiveYears()
{
var dt = new Date(2000, 1, 1);
var actual = dt.AddYears(1);
var expected = new Date(2001, 1, 1);
Assert.Equal(expected, actual);
}