Share via


Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>.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, T4, T5, T6, T7, TRest> 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, T4, T5, T6, T7, TRest> object.

Remarks

The string returned by this method takes the form (Item1, Item2, Item3, Item4, Item5, Item6, Item7, Item8…), where Item1, Item2, Item3, Item4, Item5, Item6, and Item7 represent the values of the Item1, Item2, Item3, Item4, Item5, Item6, and Item7 properties. Item8 represents the value of the Tuple<T1, T2, T3, T4, T5, T6, T7, TRest> object's Next.Item1 property. The value of any additional nested components follow Item8. If any of the property values is nulla null reference (Nothing in Visual Basic), it is represented as String.Empty.

Examples

The following example creates a 17-tuple that contains population data for the city of Detroit, Michigan, from 1860 to 1900. It then uses the ToString method to display the tuple's data.

Module Example
   Public Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      Dim from1980  = Tuple.Create(1203339, 1027974, 951270)
      Dim from1910 As New Tuple(Of Integer, Integer, Integer, Integer, Integer, Integer, Integer,  _
          Tuple(Of Integer, Integer, Integer)) _
          (465766, 993078, 1568622, 1623452, 1849568, 1670144, 1511462, from1980)
      Dim population As New Tuple(Of String, Integer, Integer, Integer, Integer, Integer, Integer,  _
          Tuple(Of Integer, Integer, Integer, Integer, Integer, Integer, Integer, Tuple(Of Integer, Integer, Integer))) _
          ("Detroit", 1860, 45619, 79577, 116340, 205876, 285704, from1910)

      outputBlock.Text &= population.ToString() & vbCrLf
   End Sub
End Module
' The example displays the following output:
'   (Detroit, 1860, 45619, 79577, 116340, 205876, 285704, 465766, 993078, 
'    1568622, 1623452, 1849568, 1670144, 1511462, 1203339, 1027974, 951270)
using System;

class Example
{
   private static System.Windows.Controls.TextBlock outputBlock;

   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {

      Example.outputBlock = outputBlock;
      Tuple<int, int, int> from1980 = Tuple.Create(1203339, 1027974, 951270);
      var from1910 = new Tuple<int, int, int, int, int, int, int, Tuple<int, int, int>>
          (465766, 993078, 1568622, 1623452, 1849568, 1670144, 1511462, from1980);
      var population = new Tuple<string, int, int, int, int, int, int,
          Tuple<int, int, int, int, int, int, int, Tuple<int, int, int>>>
          ("Detroit", 1860, 45619, 79577, 116340, 205876, 285704, from1910);

      outputBlock.Text += population.ToString() + "\n";
   }

   private static void ShowPopulationChange(int year, int newPopulation, int oldPopulation)
   {
      outputBlock.Text += String.Format("{0,5}  {1,14:N0}  {2,10:P2}", year, newPopulation,
                        ((double)(newPopulation - oldPopulation) / oldPopulation) / 10) + "\n";
   }

   private static void ShowPopulation(int year, int newPopulation)
   {
      outputBlock.Text += String.Format("{0,5}  {1,14:N0}  {2,10:P2}", year, newPopulation, "n/a") + "\n";
   }
}
// The example displays the following output:
//   (Detroit, 1860, 45619, 79577, 116340, 205876, 285704, 465766, 993078, 
//    1568622, 1623452, 1849568, 1670144, 1511462, 1203339, 1027974, 951270)

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.