本文整理汇总了C#中Time.CompareTo方法的典型用法代码示例。如果您正苦于以下问题:C# Time.CompareTo方法的具体用法?C# Time.CompareTo怎么用?C# Time.CompareTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Time
的用法示例。
在下文中一共展示了Time.CompareTo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Contains
public bool Contains(Time time)
{
if (this.From.MinuteOfDay == this.To.MinuteOfDay)
{
return false;
}
if (this.To.CompareTo(this.From) >= 0)
{
return time.CompareTo(this.From) >= 0 && time.CompareTo(this.To) <= 0;
}
return time.CompareTo(this.From) >= 0 || time.CompareTo(this.To) <= 0;
}
示例2: IsBetween
public static bool IsBetween(this DateTime dateTime, Time startTime, Time endTime)
{
var currentTime = dateTime.TimeOfTheDay();
//start time is lesser or equal than end time
if (startTime.CompareTo(endTime) <= 0) {
//currentTime should be between start time and end time
if (currentTime.CompareTo(startTime) >= 0 && currentTime.CompareTo(endTime) <= 0) {
return true;
}
return false;
} else {
//currentTime should be between end time time and start time
if (currentTime.CompareTo(startTime) >= 0 || currentTime.CompareTo(endTime) <= 0) {
return true;
}
return false;
}
}
示例3: CompareToShouldThrowException
public void CompareToShouldThrowException()
{
var date = new Time();
date.CompareTo(null);
}
示例4: CompareToTimeTest
public void CompareToTimeTest()
{
Time target = new Time(10F);
Time value = new Time(10F);
int expected = 0;
int actual;
actual = target.CompareTo(value);
Assert.AreEqual(expected, actual);
}