共用方式為


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 個 Tuple 物件的陣列,其中包含美國中狀態的名稱、其母體在 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)

備註

此方法所傳回的字串 (會採用Item1Item2Item3Item4Item5) 格式,其中Item1Item2Item3Item4Item5 分別代表 、 Item4Item2Item3Item5 屬性的值。 Item1 如果任一屬性值為 null ,則會表示為 String.Empty

適用於