Przeczytaj w języku angielskim

Udostępnij za pośrednictwem


Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>.ToString Metoda

Definicja

Zwraca ciąg reprezentujący wartość tego Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> wystąpienia.

C#
public override string ToString();

Zwraca

Reprezentacja ciągu tego Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> obiektu.

Przykłady

Poniższy przykład tworzy krotkę 17-krotkową zawierającą dane dotyczące populacji miasta Detroit, Michigan, od 1860 do 1900 roku. Następnie używa ToString metody do wyświetlania danych krotki.

C#
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)

Uwagi

Ciąg zwrócony przez tę metodę przyjmuje postać (Item1, Item2, Item3, Item4, Item5, Item6, Item7Item8...), gdzie Item1, Item2, Item3, Item4, Item5, Item6 i Item7 reprezentują wartości właściwości Item1, Item5Item3Item4Item2Item6i .Item7 Item8 reprezentuje wartość Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> właściwości obiektu Next.Item1 . Wartość wszystkich dodatkowych zagnieżdżonych składników następuje element Item8. Jeśli którakolwiek z wartości właściwości to null, jest reprezentowana jako String.Empty.

Dotyczy

Produkt Wersje
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0