Tuple<T1,T2,T3>.ToString 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回表示此 Tuple<T1,T2,T3> 实例的值的字符串。
public:
override System::String ^ ToString();
public override string ToString ();
override this.ToString : unit -> string
Public Overrides Function ToString () As String
返回
此 Tuple<T1,T2,T3> 对象的字符串表示形式。
示例
以下示例演示 了 ToString 方法。
using System;
public class Example
{
public static void Main()
{
Tuple<string, double, int>[] scores =
{ Tuple.Create("Jack", 78.8, 8),
Tuple.Create("Abbey", 92.1, 9),
Tuple.Create("Dave", 88.3, 9),
Tuple.Create("Sam", 91.7, 8),
Tuple.Create("Ed", 71.2, 5),
Tuple.Create("Penelope", 82.9, 8),
Tuple.Create("Linda", 99.0, 9),
Tuple.Create("Judith", 84.3, 9) };
Array.Sort(scores);
foreach (var score in scores)
Console.WriteLine(score.ToString());
}
}
// The example displays the following output;
// (Abbey, 92.1, 9)
// (Dave, 88.3, 9)
// (Ed, 71.2, 5)
// (Jack, 78.8, 8)
// (Judith, 84.3, 9)
// (Linda, 99, 9)
// (Penelope, 82.9, 8)
// (Sam, 91.7, 8)
open System
let scores =
[| Tuple.Create("Jack", 78.8, 8)
Tuple.Create("Abbey", 92.1, 9)
Tuple.Create("Dave", 88.3, 9)
Tuple.Create("Sam", 91.7, 8)
Tuple.Create("Ed", 71.2, 5)
Tuple.Create("Penelope", 82.9, 8)
Tuple.Create("Linda", 99.0, 9)
Tuple.Create("Judith", 84.3, 9) |]
Array.Sort scores
for score in scores do
printfn $"{score}"
// The example displays the following output
// (Abbey, 92.1, 9)
// (Dave, 88.3, 9)
// (Ed, 71.2, 5)
// (Jack, 78.8, 8)
// (Judith, 84.3, 9)
// (Linda, 99, 9)
// (Penelope, 82.9, 8)
// (Sam, 91.7, 8)
Module Example
Public Sub Main()
Dim scores() =
{ Tuple.Create("Jack", 78.8, 8),
Tuple.Create("Abbey", 92.1, 9),
Tuple.Create("Dave", 88.3, 9),
Tuple.Create("Sam", 91.7, 8),
Tuple.Create("Ed", 71.2, 5),
Tuple.Create("Penelope", 82.9, 8),
Tuple.Create("Linda", 99.0, 9),
Tuple.Create("Judith", 84.3, 9) }
Array.Sort(scores)
For Each score In scores
Console.WriteLine(score.ToString())
Next
End Sub
End Module
' The example displays the following output;
' (Abbey, 92.1, 9)
' (Dave, 88.3, 9)
' (Ed, 71.2, 5)
' (Jack, 78.8, 8)
' (Judith, 84.3, 9)
' (Linda, 99, 9)
' (Penelope, 82.9, 8)
' (Sam, 91.7, 8)
注解
此方法返回的字符串采用 Item1、Item2、Item3) (的形式,其中 Item1、Item2 和 Item3 分别表示 、 Item2和 Item3 属性的值Item1。 如果任何属性值为 null
,则表示为 String.Empty。