Share via


Tuple<T1, T2, T3>.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, T3> 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, T3> object.

Remarks

The string returned by this method takes the form (Item1, Item2, Item3), where Item1, Item2, and Item3 represent the values of the Item1, Item2, and Item3 properties, respectively. If any of the property values 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() = _
                { Tuple.Create("Jack", 78.8, 8), _
                  Tuple.Create("Abbey", 92.1, 9), _
                  Tuple.Create("Dave", 88.3, 9), _
                  Tuple.Create("Sam", 91.7, 8), _
                  Tuple.Create("Ed", 71.2, 5), _
                  Tuple.Create("Penelope", 82.9, 8), _
                  Tuple.Create("Linda", 99.0, 9), _
                  Tuple.Create("Judith", 84.3, 9) }
      Array.Sort(scores)
      For Each score In scores
         outputBlock.Text &= score.ToString() & vbCrLf
      Next
   End Sub
End Module
' The example displays the following output;
'    (Abbey, 92.1, 9)
'    (Dave, 88.3, 9)
'    (Ed, 71.2, 5)
'    (Jack, 78.8, 8)
'    (Judith, 84.3, 9)
'    (Linda, 99, 9)
'    (Penelope, 82.9, 8)
'    (Sam, 91.7, 8)
using System;

public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      Tuple<string, double, int>[] scores = 
                    { Tuple.Create("Jack", 78.8, 8),
                      Tuple.Create("Abbey", 92.1, 9), 
                      Tuple.Create("Dave", 88.3, 9),
                      Tuple.Create("Sam", 91.7, 8), 
                      Tuple.Create("Ed", 71.2, 5),
                      Tuple.Create("Penelope", 82.9, 8),
                      Tuple.Create("Linda", 99.0, 9),
                      Tuple.Create("Judith", 84.3, 9) };
      Array.Sort(scores);
      foreach (var score in scores)
         outputBlock.Text += score.ToString() + "\n";
   }
}
// The example displays the following output;
//    (Abbey, 92.1, 9)
//    (Dave, 88.3, 9)
//    (Ed, 71.2, 5)
//    (Jack, 78.8, 8)
//    (Judith, 84.3, 9)
//    (Linda, 99, 9)
//    (Penelope, 82.9, 8)
//    (Sam, 91.7, 8)

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.