Tuple<T1,T2>.ToString 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
傳回字串,表示這個 Tuple<T1,T2> 執行個體的值。
public:
override System::String ^ ToString();
public override string ToString ();
override this.ToString : unit -> string
Public Overrides Function ToString () As String
傳回
此 Tuple<T1,T2> 物件的字串表示。
範例
下列範例說明 ToString 方法。
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)
Console.WriteLine(score.ToString());
}
}
// The example displays the following output:
// (Abbey, 92)
// (Dave, 88)
// (Ed, )
// (Jack, 78)
// (Linda, 99)
// (Judith, 84)
// (Penelope, 82)
// (Sam, 91)
open System
let scores =
[| Tuple<string, Nullable<int>>("Abbey", 92)
Tuple<string, Nullable<int>>("Dave", 88)
Tuple<string, Nullable<int>>("Ed", Nullable())
Tuple<string, Nullable<int>>("Jack", 78)
Tuple<string, Nullable<int>>("Linda", 99)
Tuple<string, Nullable<int>>("Judith", 84)
Tuple<string, Nullable<int>>("Penelope", 82)
Tuple<string, Nullable<int>>("Sam", 91) |]
for score in scores do
printfn $"{score.ToString()}"
// The example displays the following output:
// (Abbey, 92)
// (Dave, 88)
// (Ed, )
// (Jack, 78)
// (Linda, 99)
// (Judith, 84)
// (Penelope, 82)
// (Sam, 91)
Module modMain
Public Sub Main()
Dim scores() As Tuple(Of String, Nullable(Of Integer)) =
{ New Tuple(Of String, Nullable(Of Integer))("Abbey", 92),
New Tuple(Of String, Nullable(Of Integer))("Dave", 88),
New Tuple(Of String, Nullable(Of Integer))("Ed", Nothing), New Tuple(Of String, Nullable(Of Integer))("Jack", 78),
New Tuple(Of String, Nullable(Of Integer))("Linda", 99),
New Tuple(Of String, Nullable(Of Integer))("Judith", 84),
New Tuple(Of String, Nullable(Of Integer))("Penelope", 82),
New Tuple(Of String, Nullable(Of Integer))("Sam", 91) }
For Each score In scores
Console.WriteLine(score.ToString())
Next
End Sub
End Module
' The example displays the following output:
' (Abbey, 92)
' (Dave, 88)
' (Ed, )
' (Jack, 78)
' (Linda, 99)
' (Judith, 84)
' (Penelope, 82)
' (Sam, 91)
備註
這個方法傳回的字串 (格式為Item1、Item2) ,其中Item1和Item2代表 和 Item2 屬性的值 Item1 。 如果任一屬性值為 null
,則表示為 String.Empty 。