Export (0) Print
Expand All

Tuple<T1, T2>.ToString Method

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

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

public override string ToString()

Return Value

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

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 null, it is represented as String.Empty.

The following example illustrates the ToString method.

using System;

public class Class1
   public static void Main()
      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)
// The example displays the following output: 
//       (Abbey, 92) 
//       (Dave, 88) 
//       (Ed, ) 
//       (Jack, 78) 
//       (Linda, 99) 
//       (Judith, 84) 
//       (Penelope, 82) 
//       (Sam, 91)

.NET Framework

Supported in: 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

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, 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.

© 2014 Microsoft