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

定義

傳回字串,表示這個 Tuple<T1,T2,T3,T4,T5> 執行個體的值。

C#
public override string ToString();

傳回

Tuple<T1,T2,T3,T4,T5> 物件的字串表示。

範例

下列範例說明 ToString 方法。 它會顯示 5 個 Tuple 物件的陣列,其中包含美國中狀態的名稱、其母體在 1990 年和 2000 年、此 10 年期間的母體變更,以及母體擴展的年率變更。

C#
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)

備註

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

適用於

產品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0