Export (0) Print
Expand All

TimeSpan.UnaryPlus Operator

Returns the specified instance of TimeSpan.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

'Declaration
Public Shared Operator + ( _
	t As TimeSpan _
) As TimeSpan
'Usage
Dim t As TimeSpan 
Dim returnValue As TimeSpan 

returnValue = +t

Parameters

t
Type: System.TimeSpan

A TimeSpan.

Return Value

Type: System.TimeSpan
Returns t.

The following code example applies the Unary Plus operator to several TimeSpan objects.

' Example of the TimeSpan.Duration( ) and TimeSpan.Negate( ) methods, 
' and the TimeSpan Unary Negation and Unary Plus operators. 
Imports System
Imports Microsoft.VisualBasic

Module DuraNegaUnaryDemo

    Const dataFmt As String = "{0,22}{1,22}{2,22}" 

    Sub ShowDurationNegate( interval As TimeSpan )

        ' Display the TimeSpan value and the results of the  
        ' Duration and Negate methods.
        Console.WriteLine( dataFmt, _
            interval, interval.Duration( ), interval.Negate( ) )
    End Sub 

    Sub Main( )

        Console.WriteLine( _
            "This example of TimeSpan.Duration( ), " & _
            "TimeSpan.Negate( ), " & vbCrLf & _
            "and the TimeSpan Unary Negation and " & _
            "Unary Plus operators " & vbCrLf & _
            "generates the following output." & vbCrLf )
        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( TimeSpan.op_UnaryPlus( _
            new TimeSpan( 0, 0, 10, -20, -30 ) ) )
        ShowDurationNegate( TimeSpan.op_UnaryPlus( _
            new TimeSpan( 0, -10, 20, -30, 40 ) ) )
        ShowDurationNegate( TimeSpan.op_UnaryNegation( _
            new TimeSpan( 1, 10, 20, 40, 160 ) ) )
        ShowDurationNegate( TimeSpan.op_UnaryNegation( _
            new TimeSpan( -10, -20, -30, -40, -50 ) ) )
    End Sub  
End Module  

' 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 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft