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

정의

4개의 요소로 구성된 튜플 또는 4중을 나타냅니다.

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

형식 매개 변수

T1

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

T2

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

T3

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

T4

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

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

설명

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

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

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

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

  • 데이터 집합에 쉽게 액세스하고 조작할 수 있도록 합니다. 다음 예제에서는 야구 투수의 Tuple<T1,T2,T3,T4> 이름, 투구한 이닝 수, 획득한 홈런 수(수비 오류 없이 득점한 실행) 및 포기한 안타를 포함하는 개체 배열을 정의합니다. 배열은 각 투수의 획득 한 실행 평균 (9 이닝 게임에서 주어진 평균 실행 수) 및 이닝 당 포기 된 안타의 평균 수를 계산하는 방법에 전달 ComputeStatistics 됩니다. 또한 이 메서드는 이러한 두 평균을 사용하여 가상의 효율성 평균을 계산합니다.

    using System;
    using System.Collections.Generic;
    
    public class Example
    {
       public static void Main()
       {
          Tuple<string, decimal, int, int>[] pitchers  =  
               { Tuple.Create("McHale, Joe", 240.1m, 221, 96),
                 Tuple.Create("Paul, Dave", 233.1m, 231, 84), 
                 Tuple.Create("Williams, Mike", 193.2m, 183, 86),
                 Tuple.Create("Blair, Jack", 168.1m, 146, 65), 
                 Tuple.Create("Henry, Walt", 140.1m, 96, 30),
                 Tuple.Create("Lee, Adam", 137.2m, 109, 45),
                 Tuple.Create("Rohr, Don", 101.0m, 110, 42) };
          Tuple<string, double, double, double>[] results= ComputeStatistics(pitchers);
    
          // Display the results.
          Console.WriteLine("{0,-20} {1,9} {2,11} {3,15}\n", 
                            "Pitcher", "ERA", "Hits/Inn.", "Effectiveness");
          foreach (var result in results)
             Console.WriteLine("{0,-20} {1,9:F2} {2,11:F2} {3,15:F2}",  
                            result.Item1, result.Item2, result.Item3, result.Item4);
       }
    
       private static Tuple<string, double, double, double>[] ComputeStatistics(Tuple<string, decimal, int, int>[] pitchers)
       {    
          var list = new List<Tuple<string, double, double, double>>();
          Tuple<string, double, double, double> result;
    
          foreach (var pitcher in pitchers)
          {
             // Decimal portion of innings pitched represents 1/3 of an inning
             double innings = (double) Math.Truncate(pitcher.Item2);
             innings = innings + (((double)pitcher.Item2 - innings) * .33);
             
             double ERA = pitcher.Item4/innings * 9;
             double hitsPerInning = pitcher.Item3/innings;
             double EI = (ERA * 2 + hitsPerInning * 9)/3;
             result = new Tuple<string, double, double, double>
                               (pitcher.Item1, ERA, hitsPerInning, EI);
             list.Add(result);
          }
          return list.ToArray();
       }
    }
    // The example displays the following output;
    //       Pitcher                    ERA   Hits/Inn.   Effectiveness
    //       
    //       McHale, Joe               3.60        0.92            5.16
    //       Paul, Dave                3.24        0.99            5.14
    //       Williams, Mike            4.01        0.95            5.52
    //       Blair, Jack               3.48        0.87            4.93
    //       Henry, Walt               1.93        0.69            3.34
    //       Lee, Adam                 2.95        0.80            4.36
    //       Rohr, Don                 3.74        1.09            5.76
    
    open System
    
    let computeStatistics (pitchers: Tuple<string, decimal, int, int>[]) =
        [| for pitcher in pitchers do
            // Decimal portion of innings pitched represents 1/3 of an inning
            let innings =  truncate (double pitcher.Item2) |> double
            let innings = innings + (double pitcher.Item2 - innings) * 0.33
            
            let ERA = double pitcher.Item4 / innings * 9.
            let hitsPerInning = double pitcher.Item3 / innings
            let EI = (ERA * 2. + hitsPerInning * 9.) / 3.
            Tuple<string, double, double, double>(pitcher.Item1, ERA, hitsPerInning, EI)|]
    
    let pitchers  =  
        [| Tuple.Create("McHale, Joe", 240.1m, 221, 96)
           Tuple.Create("Paul, Dave", 233.1m, 231, 84)
           Tuple.Create("Williams, Mike", 193.2m, 183, 86)
           Tuple.Create("Blair, Jack", 168.1m, 146, 65) 
           Tuple.Create("Henry, Walt", 140.1m, 96, 30)
           Tuple.Create("Lee, Adam", 137.2m, 109, 45)
           Tuple.Create("Rohr, Don", 101.0m, 110, 42) |]
    
    let results = computeStatistics pitchers
    
    // Display the results.
    printfn "%-20s %9s %11s %15s\n" "Pitcher" "ERA" "Hits/Inn." "Effectiveness"
    for result in results do
        printfn $"{result.Item1,-20} {result.Item2,9:F2} {result.Item3,11:F2} {result.Item4,15:F2}"
    
    // The example displays the following output
    //       Pitcher                    ERA   Hits/Inn.   Effectiveness
    //       
    //       McHale, Joe               3.60        0.92            5.16
    //       Paul, Dave                3.24        0.99            5.14
    //       Williams, Mike            4.01        0.95            5.52
    //       Blair, Jack               3.48        0.87            4.93
    //       Henry, Walt               1.93        0.69            3.34
    //       Lee, Adam                 2.95        0.80            4.36
    //       Rohr, Don                 3.74        1.09            5.76
    
    Imports System.Collections.Generic
    
    Module Example
       Public Sub Main()
          Dim pitchers() =  
                   { Tuple.Create("McHale, Joe", 240.1d, 221, 96),
                     Tuple.Create("Paul, Dave", 233.1d, 231, 84), 
                     Tuple.Create("Williams, Mike", 193.2d, 183, 86),
                     Tuple.Create("Blair, Jack", 168.1d, 146, 65), 
                     Tuple.Create("Henry, Walt", 140.1d, 96, 30),
                     Tuple.Create("Lee, Adam", 137.2d, 109, 45),
                     Tuple.Create("Rohr, Don", 101.0d, 110, 42) }
          Dim results() = ComputeStatistics(pitchers)
    
          ' Display the results.
          Console.WriteLine("{0,-20} {1,9} {2,11} {3,15}", "Pitcher", "ERA", "Hits/Inn.", "Effectiveness")
          Console.WriteLine()
          For Each result In results
             Console.WriteLine("{0,-20} {1,9:F2} {2,11:F2} {3,15:F2}",  
                            result.Item1, result.Item2, result.Item3, result.Item4)
          Next
       End Sub
       
       Private Function ComputeStatistics(pitchers() As Tuple(Of String, Decimal, Integer, Integer)) _ 
                                    As Tuple(Of String, Double, Double, Double)()
          Dim list As New List(Of Tuple(Of String, Double, Double, Double))
          Dim result As Tuple(Of String, Double, Double, Double)
    
          For Each pitcher As Tuple(Of String, Decimal, Integer, Integer) In pitchers
             ' Decimal portion of innings pitched represents 1/3 of an inning
             Dim innings As Double = CDbl(Math.Truncate(pitcher.Item2))
             innings = innings + ((pitcher.Item2 - innings) * .33)
             
             Dim ERA As Double = pitcher.Item4/innings * 9
             Dim hitsPerInning As Double = pitcher.Item3/innings
             Dim EI As Double = (ERA * 2 + hitsPerInning * 9)/3
             result = New Tuple(Of String, Double, Double, Double) _
                               (pitcher.Item1, ERA, hitsPerInning, EI)
             list.Add(result) 
          Next
          Return list.ToArray()
       End Function
    End Module
    ' The example displays the following output:
    '       Pitcher                    ERA   Hits/Inn.   Effectiveness
    '       
    '       McHale, Joe               3.60        0.92            5.16
    '       Paul, Dave                3.24        0.99            5.14
    '       Williams, Mike            4.01        0.95            5.52
    '       Blair, Jack               3.48        0.87            4.93
    '       Henry, Walt               1.93        0.69            3.34
    '       Lee, Adam                 2.95        0.80            4.36
    '       Rohr, Don                 3.74        1.09            5.76
    
  • 매개 변수(C#) 또는 ByRef 매개 변수(Visual Basic)를 사용하지 out 않고 메서드에서 여러 값을 반환합니다. 예를 들어 이전 예제에서는 개체 배열 Tuple<T1,T2,T3,T4> 에서 투수의 이름과 함께 계산된 통계를 반환합니다.

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

생성자

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

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

속성

Item1

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

Item2

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

Item3

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

Item4

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

메서드

Equals(Object)

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

GetHashCode()

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

GetType()

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

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

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

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

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

명시적 인터페이스 구현

IComparable.CompareTo(Object)

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

IStructuralComparable.CompareTo(Object, IComparer)

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

IStructuralEquatable.Equals(Object, IEqualityComparer)

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

IStructuralEquatable.GetHashCode(IEqualityComparer)

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

ITuple.Item[Int32]

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

ITuple.Length

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

확장 메서드

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

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

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

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

적용 대상

추가 정보