當前位置: 首頁>>代碼示例>>C#>>正文


C# Duration.ToTimeSpan方法代碼示例

本文整理匯總了C#中System.Duration.ToTimeSpan方法的典型用法代碼示例。如果您正苦於以下問題:C# Duration.ToTimeSpan方法的具體用法?C# Duration.ToTimeSpan怎麽用?C# Duration.ToTimeSpan使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Duration的用法示例。


在下文中一共展示了Duration.ToTimeSpan方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: TestToTimeSpan

 public void TestToTimeSpan()
 {
     Duration duration = new Duration(28, 24132.0);
     TimeSpan timeSpan = duration.ToTimeSpan();
     Assert.AreEqual(28, timeSpan.Days);
     Assert.AreEqual(6, timeSpan.Hours);
     Assert.AreEqual(42, timeSpan.Minutes);
     Assert.AreEqual(12, timeSpan.Seconds);
 }
開發者ID:slojo404,項目名稱:czml-writer,代碼行數:9,代碼來源:TestDuration.cs

示例2: TestTimeSpanCompatibility

        public void TestTimeSpanCompatibility()
        {
            TimeSpan timeSpan = TimeSpan.MinValue;
            Duration duration = new Duration(timeSpan);
            TimeSpan result = duration.ToTimeSpan();
            Assert.AreEqual(timeSpan, result);

            timeSpan = TimeSpan.Zero;
            duration = new Duration(timeSpan);
            result = duration.ToTimeSpan();
            Assert.AreEqual(timeSpan, result);

            timeSpan = TimeSpan.MaxValue;
            duration = new Duration(timeSpan);
            result = duration.ToTimeSpan();
            Assert.AreEqual(timeSpan, result);
        }
開發者ID:slojo404,項目名稱:czml-writer,代碼行數:17,代碼來源:TestDuration.cs

示例3: CancelAfter

 /// <summary>
 /// Schedules a cancel operation on this <see cref="T:System.Threading.CancellationTokenSource" /> after the specified duration.
 /// </summary>
 /// <param name="delay">The duration to wait before canceling this <see cref="T:System.Threading.CancellationTokenSource" />.</param>
 public void CancelAfter(Duration delay)
 {
     CancellationTokenSource source = _source;
     if (source != null)
         source.CancelAfter(delay.ToTimeSpan());
 }
開發者ID:webappsuk,項目名稱:CoreLibraries,代碼行數:10,代碼來源:TimedTokenSource.cs

示例4: TimedTokenSource

        /// <summary>
        /// Initializes a new instance of the <see cref="TimedTokenSource"/> class.
        /// </summary>
        /// <param name="timeout">The timeout.</param>
        /// <param name="tokens">The tokens.</param>
        public TimedTokenSource(Duration timeout, [NotNull] params CancellationToken[] tokens)
        {
            Debug.Assert(tokens != null);
            Debug.Assert(tokens.Length > 0);
            Debug.Assert(tokens.Any(t => t.CanBeCanceled));

            _timeoutSource = new CancellationTokenSource(timeout.ToTimeSpan());
            _source = CancellationTokenSource.CreateLinkedTokenSource(
                tokens.Union(new[] { _timeoutSource.Token }).ToArray());
        }
開發者ID:webappsuk,項目名稱:CoreLibraries,代碼行數:15,代碼來源:TimedTokenSource.cs

示例5: CancelAfter

 /// <summary>
 /// Schedules a cancel operation on this <see cref="CancelableTokenSource" /> after the specified duration.
 /// </summary>
 /// <param name="delay">The duration to wait before canceling this <see cref="CancelableTokenSource" />.</param>
 public void CancelAfter(Duration delay)
 {
     CancelAfter(delay.ToTimeSpan());
 }
開發者ID:webappsuk,項目名稱:CoreLibraries,代碼行數:8,代碼來源:CancelableTokenSource.cs

示例6: CancelableTokenSource

 /// <summary>
 /// Initializes a new instance of the <see cref="CancelableTokenSource"/> class.
 /// </summary>
 /// <param name="timeout">The timeout.</param>
 public CancelableTokenSource(Duration timeout)
     : base(timeout.ToTimeSpan())
 {
 }
開發者ID:webappsuk,項目名稱:CoreLibraries,代碼行數:8,代碼來源:CancelableTokenSource.cs


注:本文中的System.Duration.ToTimeSpan方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。