Export (0) Print
Expand All

Tuple(Of T1, T2).Item2 Property

Gets the value of the current Tuple(Of T1, T2) object's second component.

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

'Declaration
Public ReadOnly Property Item2 As T2

Property Value

Type: T2
The value of the current Tuple(Of T1, T2) object's second component.

You can dynamically determine the type of the Item2 component in one of two ways:

  • By calling the GetType method on the value that is returned by the Item2 property.

  • By retrieving the Type object that represents the Tuple(Of T1, T2) object, and retrieving the second element from the array that is returned by its Type.GetGenericArguments method.

The example illustrates the use of the Item1 and Item2 properties to define a method that returns multiple values in the form of a 2-tuple.

Module modMain
   Public Sub Main()
      Dim dividend, divisor As Integer 
      Dim result As Tuple(Of Integer, Integer)

      dividend = 136945 : divisor = 178
      result = IntegerDivide(dividend, divisor)
      If result IsNot Nothing Then
         Console.WriteLine("{0} \ {1} = {2}, remainder {3}", 
                           dividend, divisor, result.Item1, result.Item2)
      Else
         Console.WriteLine("{0} \ {1} = <Error>", dividend, divisor)
      End If

      dividend = Int32.MaxValue : divisor = -2073
      result = IntegerDivide(dividend, divisor)
      If result IsNot Nothing Then
         Console.WriteLine("{0} \ {1} = {2}, remainder {3}", 
                           dividend, divisor, result.Item1, result.Item2)
      Else
         Console.WriteLine("{0} \ {1} = <Error>", dividend, divisor)
      End If 
   End Sub 

   Private Function IntegerDivide(dividend As Integer, divisor As Integer) As Tuple(Of Integer, Integer)
      Try 
         Dim remainder As Integer 
         Dim quotient As Integer = Math.DivRem(dividend, divisor, remainder)
         Return New Tuple(Of Integer, Integer)(quotient, remainder)
      Catch e As DivideByZeroException
         Return Nothing 
      End Try       
   End Function 
End Module 
' The example displays the following output: 
'       136945 \ 178 = 769, remainder 63 
'       2147483647 \ -2073 = -1035930, remainder 757

.NET Framework

Supported in: 4.6, 4.5, 4

.NET Framework Client Profile

Supported in: 4

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft