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


C# TimeSpan.UnaryPlus操作符代碼示例

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


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

示例1: ShowDurationNegate

// Example of the TimeSpan.Duration( ) and TimeSpan.Negate( ) methods,
// and the TimeSpan Unary Negation and Unary Plus operators.
using System;

class DuraNegaUnaryDemo
{
    const string dataFmt = "{0,22}{1,22}{2,22}" ;

    static void ShowDurationNegate( TimeSpan interval )
    {
        // Display the TimeSpan value and the results of the 
        // Duration and Negate methods.
        Console.WriteLine( dataFmt, 
            interval, interval.Duration( ), interval.Negate( ) );
    }

    static void Main()
    {
        Console.WriteLine(
            "This example of TimeSpan.Duration( ), " +
            "TimeSpan.Negate( ), \nand the TimeSpan Unary " +
            "Negation and Unary Plus operators \n" +
            "generates the following output.\n" );
        Console.WriteLine( dataFmt, 
            "TimeSpan", "Duration( )", "Negate( )" );
        Console.WriteLine( dataFmt, 
            "--------", "-----------", "---------" );

        // Create TimeSpan objects and apply the Unary Negation
        // and Unary Plus operators to them.
        ShowDurationNegate( new TimeSpan( 1 ) );
        ShowDurationNegate( new TimeSpan( -1234567 ) );
        ShowDurationNegate( 
            + new TimeSpan( 0, 0, 10, -20, -30 ) );
        ShowDurationNegate( 
            + new TimeSpan( 0, -10, 20, -30, 40 ) );
        ShowDurationNegate( 
            - new TimeSpan( 1, 10, 20, 40, 160 ) );
        ShowDurationNegate( 
            - new TimeSpan( -10, -20, -30, -40, -50 ) );
    } 
} 

/*
This example of TimeSpan.Duration( ), TimeSpan.Negate( ),
and the TimeSpan Unary Negation and Unary Plus operators
generates the following output.

              TimeSpan           Duration( )             Negate( )
              --------           -----------             ---------
      00:00:00.0000001      00:00:00.0000001     -00:00:00.0000001
     -00:00:00.1234567      00:00:00.1234567      00:00:00.1234567
      00:09:39.9700000      00:09:39.9700000     -00:09:39.9700000
     -09:40:29.9600000      09:40:29.9600000      09:40:29.9600000
   -1.10:20:40.1600000    1.10:20:40.1600000    1.10:20:40.1600000
   10.20:30:40.0500000   10.20:30:40.0500000  -10.20:30:40.0500000
*/
開發者ID:.NET開發者,項目名稱:System,代碼行數:57,代碼來源:TimeSpan.UnaryPlus


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