Tuple<T1,T2,T3,T4,T5> 클래스

정의

5개의 요소로 구성된 튜플을 나타냅니다.

generic <typename T1, typename T2, typename T3, typename T4, typename T5>
public ref class Tuple : IComparable, System::Collections::IStructuralComparable, System::Collections::IStructuralEquatable
generic <typename T1, typename T2, typename T3, typename T4, typename T5>
public ref class Tuple : IComparable, System::Collections::IStructuralComparable, System::Collections::IStructuralEquatable, System::Runtime::CompilerServices::ITuple
public class Tuple<T1,T2,T3,T4,T5> : IComparable, System.Collections.IStructuralComparable, System.Collections.IStructuralEquatable
public class Tuple<T1,T2,T3,T4,T5> : IComparable, System.Collections.IStructuralComparable, System.Collections.IStructuralEquatable, System.Runtime.CompilerServices.ITuple
[System.Serializable]
public class Tuple<T1,T2,T3,T4,T5> : IComparable, System.Collections.IStructuralComparable, System.Collections.IStructuralEquatable
type Tuple<'T1, 'T2, 'T3, 'T4, 'T5> = class
    interface IStructuralComparable
    interface IStructuralEquatable
    interface IComparable
type Tuple<'T1, 'T2, 'T3, 'T4, 'T5> = class
    interface IStructuralComparable
    interface IStructuralEquatable
    interface IComparable
    interface ITuple
[<System.Serializable>]
type Tuple<'T1, 'T2, 'T3, 'T4, 'T5> = class
    interface IStructuralEquatable
    interface IStructuralComparable
    interface IComparable
[<System.Serializable>]
type Tuple<'T1, 'T2, 'T3, 'T4, 'T5> = class
    interface IStructuralEquatable
    interface IStructuralComparable
    interface IComparable
    interface ITuple
Public Class Tuple(Of T1, T2, T3, T4, T5)
Implements IComparable, IStructuralComparable, IStructuralEquatable
Public Class Tuple(Of T1, T2, T3, T4, T5)
Implements IComparable, IStructuralComparable, IStructuralEquatable, ITuple

형식 매개 변수

T1

튜플의 첫 번째 구성 요소 형식입니다.

T2

튜플의 두 번째 구성 요소 형식입니다.

T3

튜플의 세 번째 구성 요소 형식입니다.

T4

튜플의 네 번째 구성 요소 형식입니다.

T5

튜플의 다섯 번째 구성 요소 형식입니다.

상속
Tuple<T1,T2,T3,T4,T5>
특성
구현

설명

튜플은 값의 특정 수와 시퀀스를 갖는 데이터 구조입니다. 클래스는 Tuple<T1,T2,T3,T4,T5> 5개의 구성 요소가 있는 튜플인 5개 튜플 또는 퀸투플을 나타냅니다.

생성자 또는 정적 메서드를 Tuple<T1,T2,T3,T4,T5> 호출하여 개체를 Tuple<T1,T2,T3,T4,T5> 인스턴스화할 수 Tuple.Create<T1,T2,T3,T4,T5>(T1, T2, T3, T4, T5) 있습니다. 읽기 전용Item1, Item2, Item3Item4Item5 및 인스턴스 속성을 사용하여 튜플 구성 요소의 값을 검색할 수 있습니다.

튜플은 일반적으로 네 가지 방법으로 사용됩니다.

  • 단일 데이터 집합을 나타내려면 예를 들어 튜플은 데이터베이스 레코드를 나타낼 수 있으며 해당 구성 요소는 레코드의 개별 필드를 나타낼 수 있습니다.

  • 데이터 집합에 쉽게 액세스하고 조작할 수 있도록 합니다. 다음 예제에서는 미식 축구에서 러닝 백의 이름, 플레이한 게임 수, 캐리 수, 획득한 총 야드 수 및 해당 게임 중 득점한 터치다운을 포함하는 개체의 배열 Tuple<T1,T2,T3,T4,T5> 을 정의합니다. 배열은 각 러닝백의 게임당 캐리 수, 경기당 평균 야드, 캐리당 평균 야드 및 시도당 평균 터치다운 수를 계산하는 메서드에 전달 ComputeStatistics 됩니다.

    using System;
    using System.Collections.Generic;
    
    public class Example
    {
       public static void Main()
       {
          // Organization of runningBacks 5-tuple:
          //    Component 1: Player name
          //    Component 2: Number of games played
          //    Component 3: Number of attempts (carries)
          //    Component 4: Number of yards gained 
          //    Component 5: Number of touchdowns   
          Tuple<string, int, int, int, int>[] runningBacks =
               { Tuple.Create("Payton, Walter", 190, 3838, 16726, 110),  
                 Tuple.Create("Sanders, Barry", 153, 3062, 15269, 99),            
                 Tuple.Create("Brown, Jim", 118, 2359, 12312, 106),            
                 Tuple.Create("Dickerson, Eric", 144, 2996, 13259, 90),            
                 Tuple.Create("Faulk, Marshall", 176, 2836, 12279, 100) }; 
          // Calculate statistics.
          // Organization of runningStats 5-tuple:
          //    Component 1: Player name
          //    Component 2: Number of attempts per game
          //    Component 3: Number of yards per game
          //    Component 4: Number of yards per attempt 
          //    Component 5: Number of touchdowns per attempt   
          Tuple<string, double, double, double, double>[] runningStats  = 
              ComputeStatistics(runningBacks);
    
          // Display the result.          
          Console.WriteLine("{0,-16} {1,5} {2,6} {3,7} {4,7} {5,7} {6,7} {7,5} {8,7}\n", 
                            "Name", "Games", "Att", "Att/Gm", "Yards", "Yds/Gm",
                            "Yds/Att", "TD", "TD/Att");
          for (int ctr = 0; ctr < runningBacks.Length; ctr++)
             Console.WriteLine("{0,-16} {1,5} {2,6:N0} {3,7:N1} {4,7:N0} {5,7:N1} {6,7:N2} {7,5} {8,7:N3}\n", 
                               runningBacks[ctr].Item1, runningBacks[ctr].Item2, runningBacks[ctr].Item3, 
                               runningStats[ctr].Item2, runningBacks[ctr].Item4, runningStats[ctr].Item3, 
                               runningStats[ctr].Item4, runningBacks[ctr].Item5, runningStats[ctr].Item5);
       }
    
       private static Tuple<string, double, double, double, double>[] ComputeStatistics(
                    Tuple<string, int, int, int, int>[] players) 
       {
          Tuple<string, double, double, double, double> result; 
          var list = new List<Tuple<string, double, double, double, double>>();
          
          foreach (var player in players)
          {
             // Create result object containing player name and statistics.
             result = Tuple.Create(player.Item1,  
                                   player.Item3/((double)player.Item2), 
                                   player.Item4/((double)player.Item2),
                                   player.Item4/((double)player.Item3), 
                                   player.Item5/((double)player.Item3));
             list.Add(result);         
          }
          return list.ToArray();  
       }
    }
    // The example displays the following output:
    //    Name             Games    Att  Att/Gm   Yards  Yds/Gm Yds/Att    TD  TD/Att
    //    
    //    Payton, Walter     190  3,838    20.2  16,726    88.0    4.36   110   0.029
    //    
    //    Sanders, Barry     153  3,062    20.0  15,269    99.8    4.99    99   0.032
    //    
    //    Brown, Jim         118  2,359    20.0  12,312   104.3    5.22   106   0.045
    //    
    //    Dickerson, Eric    144  2,996    20.8  13,259    92.1    4.43    90   0.030
    //    
    //    Faulk, Marshall    176  2,836    16.1  12,279    69.8    4.33   100   0.035
    
    open System
    
    let computeStatistics (players: Tuple<string, int, int, int, int>[]) = 
        [| for player in players do
            // Create result object containing player name and statistics.
            Tuple.Create(player.Item1,  
                         double player.Item3 / double player.Item2,
                         double player.Item4 / double player.Item2,
                         double player.Item4 / double player.Item3, 
                         double player.Item5 / double player.Item3) |]
    
    
    // Organization of runningBacks 5-tuple:
    //    Component 1: Player name
    //    Component 2: Number of games played
    //    Component 3: Number of attempts (carries)
    //    Component 4: Number of yards gained 
    //    Component 5: Number of touchdowns   
    let runningBacks =
        [| Tuple.Create("Payton, Walter", 190, 3838, 16726, 110)
           Tuple.Create("Sanders, Barry", 153, 3062, 15269, 99)
           Tuple.Create("Brown, Jim", 118, 2359, 12312, 106)
           Tuple.Create("Dickerson, Eric", 144, 2996, 13259, 90)
           Tuple.Create("Faulk, Marshall", 176, 2836, 12279, 100) |]
    // Calculate statistics.
    // Organization of runningStats 5-tuple:
    //    Component 1: Player name
    //    Component 2: Number of attempts per game
    //    Component 3: Number of yards per game
    //    Component 4: Number of yards per attempt 
    //    Component 5: Number of touchdowns per attempt   
    let runningStats = computeStatistics runningBacks
    
    // Display the result.          
    printfn "%-16s %5s %6s %7s %7s %7s %7s %5s %7s\n" "Name" "Games" "Att" "Att/Gm" "Yards" "Yds/Gm" "Yds/Att" "TD" "TD/Att"
    for i = 0 to runningBacks.Length - 1 do
        printfn $"{runningBacks[i].Item1,-16} {runningBacks[i].Item2,5} {runningBacks[i].Item3,6:N0} {runningBacks[i].Item2,7:N1} {runningBacks[i].Item4,7:N0} {runningBacks[i].Item3,7:N1} {runningBacks[i].Item4,7:N2} {runningBacks[i].Item5,5} {runningBacks[i].Item5,7:N3}\n" 
    
    // The example displays the following output:
    //    Name             Games    Att  Att/Gm   Yards  Yds/Gm Yds/Att    TD  TD/Att
    //    
    //    Payton, Walter     190  3,838    20.2  16,726    88.0    4.36   110   0.029
    //    
    //    Sanders, Barry     153  3,062    20.0  15,269    99.8    4.99    99   0.032
    //    
    //    Brown, Jim         118  2,359    20.0  12,312   104.3    5.22   106   0.045
    //    
    //    Dickerson, Eric    144  2,996    20.8  13,259    92.1    4.43    90   0.030
    //    
    //    Faulk, Marshall    176  2,836    16.1  12,279    69.8    4.33   100   0.035
    
    Imports System.Collections.Generic
    
    Module Example
       Public Sub Main()
          ' Organization of runningBacks 5-tuple:
          '    Component 1: Player name
          '    Component 2: Number of games played
          '    Component 3: Number of attempts (carries)
          '    Component 4: Number of yards gained 
          '    Component 5: Number of touchdowns   
          Dim runningBacks() =
              { Tuple.Create("Payton, Walter", 190, 3838, 16726, 110),  
                Tuple.Create("Sanders, Barry", 153, 3062, 15269, 99),            
                Tuple.Create("Brown, Jim", 118, 2359, 12312, 106),            
                Tuple.Create("Dickerson, Eric", 144, 2996, 13259, 90),            
                Tuple.Create("Faulk, Marshall", 176, 2836, 12279, 100) } 
          ' Calculate statistics.
          ' Organization of runningStats 5-tuple:
          '    Component 1: Player name
          '    Component 2: Number of attempts per game
          '    Component 3: Number of yards per game
          '    Component 4: Number of yards per attempt 
          '    Component 5: Number of touchdowns per attempt   
          Dim runningStats() = ComputeStatistics(runningBacks)
    
          ' Display the result.          
          Console.WriteLine("{0,-16} {1,5} {2,6} {3,7} {4,7} {5,7} {6,7} {7,5} {8,7}", 
                            "Name", "Games", "Att", "Att/Gm", "Yards", "Yds/Gm",
                            "Yds/Att", "TD", "TD/Att")
          Console.WriteLine()
          For ctr As Integer = 0 To runningBacks.Length - 1
             Console.WriteLine("{0,-16} {1,5} {2,6:N0} {3,7:N1} {4,7:N0} {5,7:N1} {6,7:N2} {7,5} {8,7:N3}", 
                               runningBacks(ctr).Item1, runningBacks(ctr).Item2, runningBacks(ctr).Item3, 
                               runningStats(ctr).Item2, runningBacks(ctr).Item4, runningStats(ctr).Item3, 
                               runningStats(ctr).Item4, runningBacks(ctr).Item5, runningStats(ctr).Item5)
             Console.WriteLine()  
          Next     
       End Sub
    
       Private Function ComputeStatistics(players() As Tuple(Of String, Integer, Integer, Integer, Integer)) _
                        As Tuple(Of String, Double, Double, Double, Double)()
    
          Dim result As Tuple(Of String, Double, Double, Double, Double)
          Dim list As New List(Of Tuple(Of String, Double, Double, Double, Double))()
          
          For Each player In players
             ' Create result object containing player name and statistics.
             result = Tuple.Create(player.Item1,  
                                player.Item3/player.Item2, player.Item4/player.Item2,
                                player.Item4/player.Item3, player.Item5/player.Item3)
             list.Add(result)         
          Next
          Return list.ToArray()  
       End Function
    End Module
    ' The example displays the following output:
    '    Name             Games    Att  Att/Gm   Yards  Yds/Gm Yds/Att    TD  TD/Att
    '    
    '    Payton, Walter     190  3,838    20.2  16,726    88.0    4.36   110   0.029
    '    
    '    Sanders, Barry     153  3,062    20.0  15,269    99.8    4.99    99   0.032
    '    
    '    Brown, Jim         118  2,359    20.0  12,312   104.3    5.22   106   0.045
    '    
    '    Dickerson, Eric    144  2,996    20.8  13,259    92.1    4.43    90   0.030
    '    
    '    Faulk, Marshall    176  2,836    16.1  12,279    69.8    4.33   100   0.035
    
  • 매개 변수(C#) 또는 ByRef 매개 변수(Visual Basic)를 사용하지 out 않고 메서드에서 여러 값을 반환합니다. 예를 들어 이전 예제에서는 개체 배열 Tuple<T1,T2,T3,T4,T5> 에서 플레이어 이름과 함께 계산된 통계를 반환합니다.

  • 단일 매개 변수를 통해 메서드에 여러 값을 전달합니다. 예를 들어 메서드에는 Thread.Start(Object) 스레드가 시작할 때 실행되는 메서드에 하나의 값을 제공할 수 있는 단일 매개 변수가 있습니다. 메서드 인수로 개체를 Tuple<T1,T2,T3,T4,T5> 제공하는 경우 스레드의 시작 루틴에 5개의 데이터 항목을 제공할 수 있습니다.

생성자

Tuple<T1,T2,T3,T4,T5>(T1, T2, T3, T4, T5)

Tuple<T1,T2,T3,T4,T5> 클래스의 새 인스턴스를 초기화합니다.

속성

Item1

현재 Tuple<T1,T2,T3,T4,T5> 개체의 첫 번째 구성 요소 값을 가져옵니다.

Item2

현재 Tuple<T1,T2,T3,T4,T5> 개체의 두 번째 구성 요소 값을 가져옵니다.

Item3

현재 Tuple<T1,T2,T3,T4,T5> 개체의 세 번째 구성 요소 값을 가져옵니다.

Item4

현재 Tuple<T1,T2,T3,T4,T5> 개체의 네 번째 구성 요소 값을 가져옵니다.

Item5

현재 Tuple<T1,T2,T3,T4,T5> 개체의 다섯 번째 구성 요소 값을 가져옵니다.

메서드

Equals(Object)

현재 Tuple<T1,T2,T3,T4,T5> 개체가 지정된 개체와 같은지 여부를 나타내는 값을 반환합니다.

GetHashCode()

현재 Tuple<T1,T2,T3,T4,T5> 개체에 대한 해시 코드를 반환합니다.

GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

Tuple<T1,T2,T3,T4,T5> 인스턴스의 값을 나타내는 문자열을 반환합니다.

명시적 인터페이스 구현

IComparable.CompareTo(Object)

현재 Tuple<T1,T2,T3,T4,T5> 개체를 지정된 개체와 비교하고 현재 개체가 정렬 순서에 지정된 개체보다 이전인지, 이후인지 또는 같은 위치인지를 나타내는 정수를 반환합니다.

IStructuralComparable.CompareTo(Object, IComparer)

지정된 비교자를 사용하여 현재 Tuple<T1,T2,T3,T4,T5> 개체와 지정된 개체를 비교하고 정렬 순서에서 현재 개체의 위치가 지정된 개체보다 앞인지, 뒤인지 또는 동일한지를 나타내는 정수를 반환합니다.

IStructuralEquatable.Equals(Object, IEqualityComparer)

지정된 비교 메서드를 기반으로 현재 Tuple<T1,T2,T3,T4,T5> 개체가 지정된 개체와 같은지 여부를 나타내는 값을 반환합니다.

IStructuralEquatable.GetHashCode(IEqualityComparer)

지정된 계산 메서드를 사용하여 현재 Tuple<T1,T2,T3,T4,T5> 개체에 대한 해시 코드를 계산합니다.

ITuple.Item[Int32]

지정한 Tuple 요소의 값을 가져옵니다.

ITuple.Length

Tuple의 요소 수를 가져옵니다.

확장 메서드

Deconstruct<T1,T2,T3,T4,T5>(Tuple<T1,T2,T3,T4,T5>, T1, T2, T3, T4, T5)

5개 요소가 포함된 튜플을 개별 변수로 분해합니다.

ToValueTuple<T1,T2,T3,T4,T5>(Tuple<T1,T2,T3,T4,T5>)

Tuple 클래스 인스턴스를 ValueTuple 구조체 인스턴스로 변환합니다.

적용 대상

추가 정보