本文整理汇总了C#中System.Duration.CompareTo方法的典型用法代码示例。如果您正苦于以下问题:C# Duration.CompareTo方法的具体用法?C# Duration.CompareTo怎么用?C# Duration.CompareTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Duration
的用法示例。
在下文中一共展示了Duration.CompareTo方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestCompareTo
public void TestCompareTo()
{
Duration duration1 = new Duration(1, 0.0);
Duration duration2 = new Duration(1, 0.0);
Assert.IsTrue(duration1.CompareTo(duration2) == 0);
Assert.IsTrue(duration2.CompareTo(duration1) == 0);
Assert.IsTrue(duration1 >= duration2);
Assert.IsTrue(duration2 <= duration1);
Assert.IsTrue(duration1 <= duration2);
Assert.IsTrue(duration2 >= duration1);
duration2 = new Duration(2, 0.0);
Assert.IsTrue(duration1.CompareTo(duration2) < 0);
Assert.IsTrue(duration2.CompareTo(duration1) > 0);
Assert.IsTrue(duration1 < duration2);
Assert.IsTrue(duration2 > duration1);
Assert.IsTrue(duration1 <= duration2);
Assert.IsTrue(duration2 >= duration1);
duration2 = new Duration(1, 1.0);
Assert.IsTrue(duration1.CompareTo(duration2) < 0);
Assert.IsTrue(duration2.CompareTo(duration1) > 0);
Assert.IsTrue(duration1 < duration2);
Assert.IsTrue(duration2 > duration1);
Assert.IsTrue(duration1 <= duration2);
Assert.IsTrue(duration2 >= duration1);
}
示例2: TestEquality
public void TestEquality()
{
Duration first = new Duration(5, 565.0);
Duration second = new Duration(5, 565.0);
Assert.AreEqual(first, second);
Assert.IsTrue(first.Equals(second));
Assert.IsTrue(second.Equals(first));
Assert.IsTrue(first == second);
Assert.IsTrue(second == first);
Assert.IsFalse(first != second);
Assert.IsFalse(second != first);
Assert.AreEqual(0, first.CompareTo(second));
Assert.AreEqual(0, second.CompareTo(first));
first = new Duration(5, 0.00001);
second = new Duration(4, 86399.99999);
Assert.AreNotEqual(first, second);
Assert.IsFalse(first.Equals(second));
Assert.IsFalse(second.Equals(first));
Assert.IsFalse(first == second);
Assert.IsFalse(second == first);
Assert.IsTrue(first != second);
Assert.IsTrue(second != first);
Assert.AreNotEqual(0, first.CompareTo(second));
Assert.AreNotEqual(0, second.CompareTo(first));
Assert.IsTrue(first.EqualsEpsilon(second, 1e-4));
Assert.IsTrue(second.EqualsEpsilon(first, 1e-4));
// Make sure a Duration compared with a non-Duration returns false
Assert.IsFalse(first.Equals(5));
}
示例3: TestObjectCompareToNotDuration
public void TestObjectCompareToNotDuration()
{
Duration duration1 = new Duration(1, 1.0);
Assert.IsTrue(duration1.CompareTo(5) == 0);
}
示例4: TestObjectCompareTo
public void TestObjectCompareTo()
{
Duration duration1 = new Duration(1, 1.0);
Assert.IsTrue(duration1.CompareTo(null) > 0);
object duration2 = new Duration(1, 1.0);
Assert.IsTrue(duration1.CompareTo(duration2) == 0);
}
示例5: CompareToShouldThrowException
public void CompareToShouldThrowException()
{
var date = new Duration();
date.CompareTo(null);
}