Tuple<T1,T2,T3,T4,T5>.ToString 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
回傳一個字串,代表該 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 方法。 它顯示一組五元組物件,包含美國州名、1990年與2000年的人口、這十年期間的人口變化,以及每年的人口變化率。
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, Item2, Item3, Item4), Item5其中 Item1, Item2, Item3, Item4,分別Item5代表 , Item1, Item2Item3及Item4屬性的Item5值。 若任一性質值為 null,則表示為 String.Empty。