Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>.ToString 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回表示此 Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> 实例的值的字符串。
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,T6,T7,TRest> 对象的字符串表示形式。
示例
以下示例创建一个 17 元组,其中包含密歇根州底特律市从 1860 年到 1900 年的人口数据。 然后, ToString 它使用 方法来显示元组的数据。
using System;
class Example
{
static void Main(string[] args)
{
Tuple<int, int, int> from1980 = Tuple.Create(1203339, 1027974, 951270);
var from1910 = new Tuple<int, int, int, int, int, int, int, Tuple<int, int, int>>
(465766, 993078, 1568622, 1623452, 1849568, 1670144, 1511462, from1980);
var population = new Tuple<string, int, int, int, int, int, int,
Tuple<int, int, int, int, int, int, int, Tuple<int, int, int>>>
("Detroit", 1860, 45619, 79577, 116340, 205876, 285704, from1910);
Console.WriteLine(population.ToString());
}
private static void ShowPopulationChange(int year, int newPopulation, int oldPopulation)
{
Console.WriteLine("{0,5} {1,14:N0} {2,10:P2}", year, newPopulation,
((double)(newPopulation - oldPopulation) / oldPopulation) / 10);
}
private static void ShowPopulation(int year, int newPopulation)
{
Console.WriteLine("{0,5} {1,14:N0} {2,10:P2}", year, newPopulation, "n/a");
}
}
// The example displays the following output:
// (Detroit, 1860, 45619, 79577, 116340, 205876, 285704, 465766, 993078,
// 1568622, 1623452, 1849568, 1670144, 1511462, 1203339, 1027974, 951270)
open System
let showPopulation year newPopulation =
printfn $"""{year,5} {newPopulation,14:N0} {"n/a",10:P2}"""
let showPopulationChange year newPopulation oldPopulation =
printfn $"{year,5} {newPopulation,14:N0} {(double (newPopulation - oldPopulation) / oldPopulation) / 10.,10:P2}"
let from1980 = Tuple.Create(1203339, 1027974, 951270)
let from1910 =
new Tuple<int, int, int, int, int, int, int, Tuple<int, int, int>>(465766, 993078, 1568622, 1623452, 1849568, 1670144, 1511462, from1980)
let population =
new Tuple<string, int, int, int, int, int, int, Tuple<int, int, int, int, int, int, int, Tuple<int, int, int>>>("Detroit", 1860, 45619, 79577, 116340, 205876, 285704, from1910)
printfn $"{population}"
// The example displays the following output:
// (Detroit, 1860, 45619, 79577, 116340, 205876, 285704, 465766, 993078,
// 1568622, 1623452, 1849568, 1670144, 1511462, 1203339, 1027974, 951270)
Module Example
Sub Main()
Dim from1980 As Tuple(Of Integer, Integer, Integer) =
Tuple.Create(1203339, 1027974, 951270)
Dim from1910 As New Tuple(Of Integer, Integer, Integer, Integer, Integer, Integer, Integer, _
Tuple(Of Integer, Integer, Integer)) _
(465766, 993078, 1568622, 1623452, 1849568, 1670144, 1511462, from1980)
Dim population As New Tuple(Of String, Integer, Integer, Integer, Integer, Integer, Integer, _
Tuple(Of Integer, Integer, Integer, Integer, Integer, Integer, Integer, Tuple(Of Integer, Integer, Integer))) _
("Detroit", 1860, 45619, 79577, 116340, 205876, 285704, from1910)
Console.WriteLine(population.ToString())
End Sub
End Module
' The example displays the following output:
' (Detroit, 1860, 45619, 79577, 116340, 205876, 285704, 465766, 993078,
' 1568622, 1623452, 1849568, 1670144, 1511462, 1203339, 1027974, 951270)
注解
此方法返回的字符串 (采用 Item1、Item2、Item3、Item4Item5, Item6, Item7
、Item8...) 的形式,其中 Item1、Item2、Item3、Item4、Item5、Item6 和 Item7 表示 、、、Item6Item5Item4Item3、 和 Item7 属性的值。Item1Item2
Item8 表示对象的 Next.Item1
属性的值Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>。 任何其他嵌套组件的值都跟在 Item8 后面。 如果任何属性值为 null
,则表示为 String.Empty。