Tuple<T1,T2,T3,T4,T5>.ToString 方法

定义

返回表示此 Tuple<T1,T2,T3,T4,T5> 实例的值的字符串。

public:
 override System::String ^ ToString();
public override string ToString ();
override this.ToString : unit -> string
Public Overrides Function ToString () As String

返回

Tuple<T1,T2,T3,T4,T5> 对象的字符串表示形式。

示例

以下示例演示 了 ToString 方法。 它显示包含 5 元组对象的数组,这些对象包含美国中某个状态的名称、其 1990 年和 2000 年的人口、此 10 年期间的人口变化以及总体年变化率。

using System;

public class Example
{
   public static void Main()
   {
      // Define array of tuples reflecting population change by state, 1990-2000.
      Tuple<string, int, int, int, double>[] populationChanges = 
           { Tuple.Create("California", 29760021, 33871648, 4111627, 13.8), 
             Tuple.Create("Illinois", 11430602, 12419293, 988691, 8.6), 
             Tuple.Create("Washington", 4866692, 5894121, 1027429, 21.1) };
      // Display each tuple.
      foreach (var item in populationChanges)
         Console.WriteLine(item.ToString());
   }
}
// The example displays the following output:
//       (California, 29760021, 33871648, 4111627, 13.8)
//       (Illinois, 11430602, 12419293, 988691, 8.6)
//       (Washington, 4866692, 5894121, 1027429, 21.1)
open System

// Define array of tuples reflecting population change by state, 1990-2000.
let populationChanges = 
    [| Tuple.Create("California", 29760021, 33871648, 4111627, 13.8) 
       Tuple.Create("Illinois", 11430602, 12419293, 988691, 8.6)
       Tuple.Create("Washington", 4866692, 5894121, 1027429, 21.1) |]
// Display each tuple.
for item in populationChanges do
    printfn $"{item.ToString()}"
// The example displays the following output:
//       (California, 29760021, 33871648, 4111627, 13.8)
//       (Illinois, 11430602, 12419293, 988691, 8.6)
//       (Washington, 4866692, 5894121, 1027429, 21.1)
Module Example
   Public Sub Main()
      ' Define array of tuples reflecting population change by state, 1990-2000.
      Dim populationChanges() = 
            { Tuple.Create("California", 29760021, 33871648, 4111627, 13.8),
              Tuple.Create("Illinois", 11430602, 12419293, 988691, 8.6),
              Tuple.Create("Washington", 4866692, 5894121, 1027429, 21.1) }
      ' Display each tuple.
      For Each item In populationChanges
         Console.WriteLine(item.ToString())
      Next                                                                    
   End Sub
End Module
' The example displays the following output:
'       (California, 29760021, 33871648, 4111627, 13.8)
'       (Illinois, 11430602, 12419293, 988691, 8.6)
'       (Washington, 4866692, 5894121, 1027429, 21.1)

注解

此方法返回的字符串采用 Item1、Item2Item3Item4Item5、) (其中 Item1Item2Item3Item4) (的形式,并Item5分别表示 、、Item2Item3Item4Item5 属性的值。Item1 如果任何属性值为 null,则表示为 String.Empty

适用于