Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>.Rest 속성

정의

현재 Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> 개체의 나머지 구성 요소를 가져옵니다.

public:
 property TRest Rest { TRest get(); };
public TRest Rest { get; }
member this.Rest : 'Rest
Public ReadOnly Property Rest As TRest

속성 값

TRest

현재 Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> 개체의 나머지 구성 요소입니다.

예제

다음 예제에서는 1860년부터 2000까지 미시간 주 디트로이트 시의 인구 데이터를 포함하는 17개의 튜플 개체를 만듭니다. 17 튜플의 일곱 번째 구성 요소는 1900 년 인구입니다. 이 예제에서는 속성을 사용하여 Rest 8번째에서 14번째 구성 요소의 값을 검색하고 중첩된 Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> 개체의 속성을 사용하여 Rest 나머지 구성 요소의 값을 검색합니다.

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 of {0}", population.Item1);
        Console.WriteLine();
        Console.WriteLine("{0,5}  {1,14}  {2,10}", "Year", "Population", "Change");

        int year = population.Item2;
        ShowPopulation(year, population.Item3);
        year += 10;
        ShowPopulationChange(year, population.Item4, population.Item3);
        year += 10;
        ShowPopulationChange(year, population.Item5, population.Item4);
        year += 10;
        ShowPopulationChange(year, population.Item6, population.Item5);
        year += 10;
        ShowPopulationChange(year, population.Item7, population.Item6);
        year += 10;
        ShowPopulationChange(year, population.Rest.Item1, population.Item7);
        year += 10;
        ShowPopulationChange(year, population.Rest.Item2, population.Rest.Item1);
        year += 10;
        ShowPopulationChange(year, population.Rest.Item3, population.Rest.Item2);
        year += 10;
        ShowPopulationChange(year, population.Rest.Item4, population.Rest.Item3);
        year += 10;
        ShowPopulationChange(year, population.Rest.Item5, population.Rest.Item4);
        year += 10;
        ShowPopulationChange(year, population.Rest.Item6, population.Rest.Item5);
        year += 10;
        ShowPopulationChange(year, population.Rest.Item7, population.Rest.Item6);
        year += 10;
        ShowPopulationChange(year, population.Rest.Rest.Item1, population.Rest.Item7);
        year += 10;
        ShowPopulationChange(year, population.Rest.Rest.Item2, population.Rest.Rest.Item1);
        year += 10;
        ShowPopulationChange(year, population.Rest.Rest.Item3, population.Rest.Rest.Item2);
    }

    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:
//
//    Population of Detroit
//    Year      Population      Change
//    1860          45,619         n/a
//    1870          79,577      7.44 %
//    1880         116,340      4.62 %
//    1890         205,876      7.70 %
//    1900         285,704      3.88 %
//    1910         465,766      6.30 %
//    1920         993,078     11.32 %
//    1930       1,568,622      5.80 %
//    1940       1,623,452      0.35 %
//    1950       1,849,568      1.39 %
//    1960       1,670,144     -0.97 %
//    1970       1,511,462     -0.95 %
//    1980       1,203,339     -2.04 %
//    1990       1,027,974     -1.46 %
//    2000         951,270     -0.75 %
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 of {population.Item1}\n"
printfn "%5s  %14s  %10s" "Year" "Population" "Change"

do
    let year = population.Item2
    showPopulation year population.Item3
    let year = year + 10
    showPopulationChange year population.Item4 population.Item3
    let year = year + 10
    showPopulationChange year population.Item5 population.Item4
    let year = year + 10
    showPopulationChange year population.Item6 population.Item5
    let year = year + 10
    showPopulationChange year population.Item7 population.Item6
    let year = year + 10
    showPopulationChange year population.Rest.Item1 population.Item7
    let year = year + 10
    showPopulationChange year population.Rest.Item2 population.Rest.Item1
    let year = year + 10
    showPopulationChange year population.Rest.Item3 population.Rest.Item2
    let year = year + 10
    showPopulationChange year population.Rest.Item4 population.Rest.Item3
    let year = year + 10
    showPopulationChange year population.Rest.Item5 population.Rest.Item4
    let year = year + 10
    showPopulationChange year population.Rest.Item6 population.Rest.Item5
    let year = year + 10
    showPopulationChange year population.Rest.Item7 population.Rest.Item6
    let year = year + 10
    showPopulationChange year population.Rest.Rest.Item1 population.Rest.Item7
    let year = year + 10
    showPopulationChange year population.Rest.Rest.Item2 population.Rest.Rest.Item1
    let year = year + 10
    showPopulationChange year population.Rest.Rest.Item3 population.Rest.Rest.Item2

// The example displays the following output:
//
//    Population of Detroit
//    Year      Population      Change
//    1860          45,619         n/a
//    1870          79,577      7.44 %
//    1880         116,340      4.62 %
//    1890         205,876      7.70 %
//    1900         285,704      3.88 %
//    1910         465,766      6.30 %
//    1920         993,078     11.32 %
//    1930       1,568,622      5.80 %
//    1940       1,623,452      0.35 %
//    1950       1,849,568      1.39 %
//    1960       1,670,144     -0.97 %
//    1970       1,511,462     -0.95 %
//    1980       1,203,339     -2.04 %
//    1990       1,027,974     -1.46 %
//    2000         951,270     -0.75 %
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 of {0}", population.Item1)
        Console.WriteLine()
        Console.WriteLine("{0,5}  {1,14}  {2,10}", "Year", "Population", "Change")

        Dim year As Integer = population.Item2
        ShowPopulation(year, population.Item3)
        year += 10
        ShowPopulationChange(year, population.Item4, population.Item3)
        year += 10
        ShowPopulationChange(year, population.Item5, population.Item4)
        year += 10
        ShowPopulationChange(year, population.Item6, population.Item5)
        year += 10
        ShowPopulationChange(year, population.Item7, population.Item6)
        year += 10
        ShowPopulationChange(year, population.Rest.Item1, population.Item7)
        year += 10
        ShowPopulationChange(year, population.Rest.Item2, population.Rest.Item1)
        year += 10
        ShowPopulationChange(year, population.Rest.Item3, population.Rest.Item2)
        year += 10
        ShowPopulationChange(year, population.Rest.Item4, population.Rest.Item3)
        year += 10
        ShowPopulationChange(year, population.Rest.Item5, population.Rest.Item4)
        year += 10
        ShowPopulationChange(year, population.Rest.Item6, population.Rest.Item5)
        year += 10
        ShowPopulationChange(year, population.Rest.Item7, population.Rest.Item6)
        year += 10
        ShowPopulationChange(year, population.Rest.Rest.Item1, population.Rest.Item7)
        year += 10
        ShowPopulationChange(year, population.Rest.Rest.Item2, population.Rest.Rest.Item1)
        year += 10
        ShowPopulationChange(year, population.Rest.Rest.Item3, population.Rest.Rest.Item2)
    End Sub

    Private Sub ShowPopulationChange(ByVal year As Integer, ByVal newPopulation As Integer, ByVal oldPopulation As Integer)
        Console.WriteLine("{0,5}  {1,14:N0}  {2,10:P2}", year, newPopulation,
                          (newPopulation - oldPopulation) / oldPopulation / 10)
    End Sub

    Private Sub ShowPopulation(ByVal year As Integer, ByVal newPopulation As Integer)
        Console.WriteLine("{0,5}  {1,14:N0}  {2,10:P2}", year, newPopulation, "n/a")
    End Sub
End Module
' The example displays the following output:
'
'    Population of Detroit
'    Year      Population      Change
'    1860          45,619         n/a
'    1870          79,577      7.44 %
'    1880         116,340      4.62 %
'    1890         205,876      7.70 %
'    1900         285,704      3.88 %
'    1910         465,766      6.30 %
'    1920         993,078     11.32 %
'    1930       1,568,622      5.80 %
'    1940       1,623,452      0.35 %
'    1950       1,849,568      1.39 %
'    1960       1,670,144     -0.97 %
'    1970       1,511,462     -0.95 %
'    1980       1,203,339     -2.04 %
'    1990       1,027,974     -1.46 %
'    2000         951,270     -0.75 %

설명

이 속성은 Rest 튜플의 n 번째 구성 요소인 8번째에 액세스할 수 있는 중첩된 Tuple 개체를 반환합니다. 튜플의 총 구성 요소 수에 따라 중첩된 Tuple 개체의 through Item7 속성에서 8번째에서 14번째 구성 요소의 Item1 값을 검색할 수 있습니다. 그런 다음 중첩된 Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> 개체의 속성을 사용하여 Rest 다음 중첩 수준에서 개체를 검색 Tuple 할 수 있습니다.

형식 이름에서 숫자를 추출하여 속성에서 반환되는 Tuple 중첩 개체의 Rest 구성 요소 수를 동적으로 확인할 수 있습니다. 다음 예제에서 이에 대해 설명합니다.

Imports System.Reflection

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)
      
        ShowComponentCount(population)
   End Sub
   
   Private Sub ShowComponentCount(tuple As Object) 
      Static ctr As Integer = 0
      Static totalComponents As Integer = 0
      Dim components As Integer = 0
      
      ctr += 1
      Dim name As String = tuple.GetType().Name
      components += Int32.Parse(name.Substring(name.IndexOf("`") + 1))
      If components = 8 Then
         totalComponents += 7
         Console.WriteLine("The tuple at level {0} has 7 components.", ctr)
         ShowComponentCount(tuple.Rest)
      Else
         totalComponents += components
         Console.WriteLine("The tuple at level {0} has {1} components.", 
                           ctr, components)
         Console.WriteLine("Total components in tuple: {0}", totalComponents)
      End If      
   End Sub        
End Module
' The example displays the following output:
'       The tuple at level 1 has 7 components.
'       The tuple at level 2 has 7 components.
'       The tuple at level 3 has 3 components.
'       Total components in tuple: 17

적용 대상