csharp 测试一段时间是否重叠
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 测试一段时间是否重叠相关的知识,希望对你有一定的参考价值。
<span style="color: #008080; font-style: italic;">/// <summary></span>
<span style="color: #008080; font-style: italic;">/// Tests if two given periods overlap each other.</span>
<span style="color: #008080; font-style: italic;">/// </summary></span>
<span style="color: #008080; font-style: italic;">/// <param name="BS">Base period start</param></span>
<span style="color: #008080; font-style: italic;">/// <param name="BE">Base period end</param></span>
<span style="color: #008080; font-style: italic;">/// <param name="TS">Test period start</param></span>
<span style="color: #008080; font-style: italic;">/// <param name="TE">Test period end</param></span>
<span style="color: #008080; font-style: italic;">/// <returns></span>
<span style="color: #008080; font-style: italic;">/// <c>true</c> if the periods overlap; otherwise, <c>false</c>.</span>
<span style="color: #008080; font-style: italic;">/// </returns></span>
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">bool</span> TimePeriodOverlap<span style="color: #000000;">(</span>DateTime BS, DateTime BE, DateTime TS, DateTime TE<span style="color: #000000;">)</span>
<span style="color: #000000;">{</span>
<span style="color: #008080; font-style: italic;">// More simple?</span>
<span style="color: #008080; font-style: italic;">// return !((TS < BS && TE < BS) || (TS > BE && TE > BE));</span>
<span style="color: #008080; font-style: italic;">// The version below, without comments </span>
<span style="color: #008080; font-style: italic;">/*
return (
(TS >= BS && TS < BE) || (TE <= BE && TE > BS) || (TS <= BS && TE >= BE)
);
*/</span>
<span style="color: #0600FF;">return</span> <span style="color: #000000;">(</span>
<span style="color: #008080; font-style: italic;">// 1. Case:</span>
<span style="color: #008080; font-style: italic;">//</span>
<span style="color: #008080; font-style: italic;">// TS-------TE</span>
<span style="color: #008080; font-style: italic;">// BS------BE </span>
<span style="color: #008080; font-style: italic;">//</span>
<span style="color: #008080; font-style: italic;">// TS is after BS but before BE</span>
<span style="color: #000000;">(</span>TS >= BS && TS < BE<span style="color: #000000;">)</span>
|| <span style="color: #008080; font-style: italic;">// or</span>
<span style="color: #008080; font-style: italic;">// 2. Case</span>
<span style="color: #008080; font-style: italic;">//</span>
<span style="color: #008080; font-style: italic;">// TS-------TE</span>
<span style="color: #008080; font-style: italic;">// BS---------BE</span>
<span style="color: #008080; font-style: italic;">//</span>
<span style="color: #008080; font-style: italic;">// TE is before BE but after BS</span>
<span style="color: #000000;">(</span>TE <= BE && TE > BS<span style="color: #000000;">)</span>
|| <span style="color: #008080; font-style: italic;">// or</span>
<span style="color: #008080; font-style: italic;">// 3. Case</span>
<span style="color: #008080; font-style: italic;">//</span>
<span style="color: #008080; font-style: italic;">// TS----------TE</span>
<span style="color: #008080; font-style: italic;">// BS----BE</span>
<span style="color: #008080; font-style: italic;">//</span>
<span style="color: #008080; font-style: italic;">// TS is before BS and TE is after BE</span>
<span style="color: #000000;">(</span>TS <= BS && TE >= BE<span style="color: #000000;">)</span>
<span style="color: #000000;">)</span>;
<span style="color: #000000;">}</span>
以上是关于csharp 测试一段时间是否重叠的主要内容,如果未能解决你的问题,请参考以下文章
csharp 此控制台应用程序测试是否在SharePoint中使用内容类型
csharp C#转换为HTML和HTML的基本HTML Helper类,提供Extensions以测试String是否包含HTML。
csharp 对于那些需要在一段时间内创建DropDownList的时候,您可以通过“Enumerable.Range”轻松完成。样本c