本文整理汇总了C#中System.TimeSpan.Negate方法的典型用法代码示例。如果您正苦于以下问题:C# TimeSpan.Negate方法的具体用法?C# TimeSpan.Negate怎么用?C# TimeSpan.Negate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.TimeSpan
的用法示例。
在下文中一共展示了TimeSpan.Negate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
*/
示例2: TimeSpan.Negate()
//引入命名空间
using System;
class MainClas
{
public static void Main()
{
TimeSpan myTimeSpan13 = new TimeSpan(1, 10, 13);
TimeSpan myTimeSpan14 = new TimeSpan(2, 6, 10);
TimeSpan myTimeSpan15 = myTimeSpan13.Subtract(myTimeSpan14);
Console.WriteLine("myTimeSpan15.Negate() = " + myTimeSpan15.Negate());
Console.WriteLine("myTimeSpan14.Negate() = " + myTimeSpan14.Negate());
}
}