# TimeSpan.Negate メソッド

2013/12/12

このインスタンスの値とは符号が逆の値を持つ新しい TimeSpan を返します。

Namespace:  System
アセンブリ:  mscorlib (mscorlib.dll 内)

## 構文

```public TimeSpan Negate()
```

#### 戻り値

このインスタンスの値と絶対値が同じで、逆の符号を持つ新しいオブジェクト。

## 例外

OverflowException

このインスタンスの値と符号が逆の値を TimeSpan で表すことはできません。つまり、このインスタンスの値が MinValue になります。

## 例

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

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

static void ShowDurationNegate(System.Windows.Controls.TextBlock outputBlock, TimeSpan interval)
{
// Display the TimeSpan value and the results of the
// Duration and Negate methods.
outputBlock.Text += String.Format(dataFmt,
interval, interval.Duration(), interval.Negate()) + "\n";
}

public static void Demo(System.Windows.Controls.TextBlock outputBlock)
{
outputBlock.Text += String.Format(
"This example of TimeSpan.Duration( ), " +
"TimeSpan.Negate( ), \nand the TimeSpan Unary " +
"Negation and Unary Plus operators \n" +
"generates the following output.\n") + "\n";
outputBlock.Text += String.Format(dataFmt,
"TimeSpan", "Duration( )", "Negate( )") + "\n";
outputBlock.Text += String.Format(dataFmt,
"--------", "-----------", "---------") + "\n";

// Create TimeSpan objects and apply the Unary Negation
// and Unary Plus operators to them.
ShowDurationNegate(outputBlock, new TimeSpan(1));
ShowDurationNegate(outputBlock, new TimeSpan(-1234567));
ShowDurationNegate(outputBlock,
new TimeSpan(0, 0, 10, -20, -30));
ShowDurationNegate(outputBlock,
new TimeSpan(0, -10, 20, -30, 40));
ShowDurationNegate(outputBlock,
new TimeSpan(1, 10, 20, 40, 160));
ShowDurationNegate(outputBlock,
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
*/

```

## バージョン情報

#### Windows Phone OS

サポート: 8.0, 7.1, 7.0

Windows Phone