Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>.ToString Método

Definición

Devuelve una cadena que representa el valor de esta instancia de 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

Devoluciones

Representación de cadena del objeto Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> en cuestión.

Ejemplos

En el ejemplo siguiente se crea una tupla de 17 que contiene datos de población para la ciudad de Detroit, Michigan, de 1860 a 1900. A continuación, usa el ToString método para mostrar los datos de la tupla.

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)

Comentarios

La cadena devuelta por este método toma el formato (Item1, Item2, Item3, Item4, Item5, Item6, Item7, Item8...), donde Item1, Item2, Item3, Item4, Item5, Item6 y Item7 representan los valores de las Item1propiedades , , Item5Item3Item4Item2, Item6y .Item7 Item8 representa el valor de la Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> propiedad del Next.Item1 objeto. El valor de cualquier componente anidado adicional sigue Item8. Si alguno de los valores de propiedad es null, se representa como String.Empty.

Se aplica a