本文整理汇总了C#中Duration.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# Duration.Equals方法的具体用法?C# Duration.Equals怎么用?C# Duration.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Duration
的用法示例。
在下文中一共展示了Duration.Equals方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestDurationClass
public void TestDurationClass()
{
var firstDuration = new Duration(200, TimeUnit.Minutes);
Check.That(firstDuration.RawDuration).IsEqualTo(200);
Check.That(firstDuration.Unit).IsEqualTo(TimeUnit.Minutes);
Check.That(firstDuration.ToString()).IsEqualTo("200 Minutes");
Check.That(firstDuration > new Duration(100, TimeUnit.Seconds)).IsTrue();
Check.That(firstDuration < new Duration(100, TimeUnit.Hours)).IsTrue();
var anotherDurationWithSameValue = new Duration(200, TimeUnit.Minutes);
// test objects override
Check.That(firstDuration.GetHashCode()).IsEqualTo(anotherDurationWithSameValue.GetHashCode());
Check.That(firstDuration).IsEqualTo(anotherDurationWithSameValue);
Check.That(anotherDurationWithSameValue.Equals(firstDuration)).IsTrue();
Check.That(anotherDurationWithSameValue == firstDuration).IsTrue();
Check.That(anotherDurationWithSameValue.Equals(null)).IsFalse();
Check.That(anotherDurationWithSameValue.Equals(20)).IsFalse();
Check.That(anotherDurationWithSameValue.Equals((object)firstDuration)).IsTrue();
}
示例2: TestDurationClass
public void TestDurationClass()
{
var test = new Duration(200, TimeUnit.Minutes);
Assert.AreEqual(200, test.RawDuration);
Assert.AreEqual(TimeUnit.Minutes, test.Unit);
Assert.AreEqual("200 Minutes", test.ToString());
Assert.IsTrue(test > new Duration(100, TimeUnit.Seconds));
Assert.IsTrue(test < new Duration(100, TimeUnit.Hours));
var altDuration = new Duration(200, TimeUnit.Minutes);
// test objects override
Assert.AreEqual(altDuration.GetHashCode(), test.GetHashCode());
Assert.AreEqual(altDuration, test);
Assert.IsTrue(altDuration.Equals(test));
Assert.IsTrue(altDuration == test);
Assert.IsFalse(altDuration.Equals(null));
Assert.IsFalse(altDuration.Equals(20));
Assert.IsTrue(altDuration.Equals((object)test));
}
示例3: Equals
public static bool Equals(Duration t1, Duration t2)
{
return t1.Equals(t2);
}
示例4: Equals
//=====================================================================
/// <summary>
/// Returns a value indicating whether two specified instances of <c>Duration</c> are equal
/// </summary>
/// <param name="d1">The first duration to compare</param>
/// <param name="d2">The second duration to compare</param>
/// <returns>Returns true if the durations are equal, false if they are not</returns>
public static bool Equals(Duration d1, Duration d2)
{
if((object)d1 == null && (object)d2 == null)
return true;
if((object)d1 == null)
return false;
return d1.Equals(d2);
}