Compartilhar via


Tuple<T1, T2>.ToString Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Returns a string that represents the value of this Tuple<T1, T2> instance.

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

Syntax

'Declaration
Public Overrides Function ToString As String
public override string ToString()

Return Value

Type: System.String
The string representation of this Tuple<T1, T2> object.

Remarks

The string returned by this method takes the form (Item1, Item2), where Item1 and Item2 represent the values of the Item1 and Item2 properties. If either property value is nulla null reference (Nothing in Visual Basic), it is represented as String.Empty.

Examples

The following example illustrates the ToString method.

Module Example
   Public Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      Dim scores() As Tuple(Of String, Nullable(Of Integer)) = _
                      { New Tuple(Of String, Nullable(Of Integer))("Abbey", 92), _ 
                        New Tuple(Of String, Nullable(Of Integer))("Dave", 88), _
                        New Tuple(Of String, Nullable(Of Integer))("Ed", Nothing), _
                        New Tuple(Of String, Nullable(Of Integer))("Jack", 78), _
                        New Tuple(Of String, Nullable(Of Integer))("Linda", 99), _
                        New Tuple(Of String, Nullable(Of Integer))("Judith", 84), _
                        New Tuple(Of String, Nullable(Of Integer))("Penelope", 82), _
                        New Tuple(Of String, Nullable(Of Integer))("Sam", 91) } 
      For Each score In scores
         outputBlock.Text &= score.ToString() & vbCrLf
      Next
   End Sub
End Module
' The example displays the following output:
'       (Abbey, 92)
'       (Dave, 88)
'       (Ed, )
'       (Jack, 78)
'       (Linda, 99)
'       (Judith, 84)
'       (Penelope, 82)
'       (Sam, 91)
using System;

public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      Tuple<string, Nullable<int>>[] scores = 
                      { new Tuple<string, Nullable<int>>("Abbey", 92), 
                        new Tuple<string, Nullable<int>>("Dave", 88),
                        new Tuple<string, Nullable<int>>("Ed", null),
                        new Tuple<string, Nullable<int>>("Jack", 78),
                        new Tuple<string, Nullable<int>>("Linda", 99),
                        new Tuple<string, Nullable<int>>("Judith", 84), 
                        new Tuple<string, Nullable<int>>("Penelope", 82),
                        new Tuple<string, Nullable<int>>("Sam", 91) };
      foreach (var score in scores)
         outputBlock.Text += score.ToString() + "\n";
   }
}
// The example displays the following output:
//       (Abbey, 92)
//       (Dave, 88)
//       (Ed, )
//       (Jack, 78)
//       (Linda, 99)
//       (Judith, 84)
//       (Penelope, 82)
//       (Sam, 91)

Version Information

Silverlight

Supported in: 5, 4

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.