本文整理汇总了C#中System.Date.CompareTo方法的典型用法代码示例。如果您正苦于以下问题:C# Date.CompareTo方法的具体用法?C# Date.CompareTo怎么用?C# Date.CompareTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Date
的用法示例。
在下文中一共展示了Date.CompareTo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompareTo
public void CompareTo()
{
var firstDate = new Date(2011, 1, 1);
var sameAsFirstDate = new Date(2011, 1, 1);
var laterDate = new Date(2011, 1, 2);
Expect(firstDate.CompareTo(sameAsFirstDate), Is.EqualTo(0));
Expect(firstDate.CompareTo(laterDate), Is.EqualTo(-1));
Expect(laterDate.CompareTo(firstDate), Is.EqualTo(1));
var min = new[] {laterDate, firstDate}.Min();
Expect(min, Is.EqualTo(firstDate));
}
示例2: TestDateCompareToInvalidTarget
public void TestDateCompareToInvalidTarget()
{
Date date = new Date(1, 1, 1);
DateTimeOffset now = DateTimeOffset.Now;
Action test = () => date.CompareTo(now);
test.ShouldThrow<ArgumentException>().WithMessage(Strings.Date_InvalidCompareToTarget(now));
}
示例3: op_CompareTo_DateTime
public void op_CompareTo_DateTime(int expected,
string date)
{
var obj = new Date(2012, 5, 30);
var other = XmlConvert.ToDateTime(date, XmlDateTimeSerializationMode.Utc);
Assert.Equal(expected, obj.CompareTo(other));
}
示例4: CompareToShouldThrowException
public void CompareToShouldThrowException()
{
var date = new Date();
date.CompareTo(null);
}