Tuple<T1,T2,T3,T4,T5> Classe
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Rappresenta una tupla a 5 o una quintupla.
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
Parametri di tipo
- T1
Tipo del primo componente della tupla.
- T2
Tipo del secondo componente della tupla.
- T3
Tipo del terzo componente della tupla.
- T4
Tipo del quarto componente della tupla.
- T5
Tipo del quinto componente della tupla.
- Ereditarietà
-
Tuple<T1,T2,T3,T4,T5>
- Attributi
- Implementazioni
Commenti
Una tupla è una struttura di dati con un numero e una sequenza di valori specifici. La Tuple<T1,T2,T3,T4,T5> classe rappresenta una tupla a 5 o una quintupla, ovvero una tupla con cinque componenti.
È possibile creare un'istanza di un Tuple<T1,T2,T3,T4,T5> oggetto chiamando il Tuple<T1,T2,T3,T4,T5> costruttore o il metodo statico Tuple.Create<T1,T2,T3,T4,T5>(T1, T2, T3, T4, T5) . È possibile recuperare il valore dei componenti della tupla usando le proprietà dell'istanza di sola Item1lettura, , Item2Item3, Item4, e Item5 .
Le tuple vengono comunemente usate in quattro modi diversi:
Per rappresentare un singolo set di dati. Ad esempio, una tupla può rappresentare un record di database e i relativi componenti possono rappresentare singoli campi del record.
Per semplificare l'accesso e la manipolazione di un set di dati. Nell'esempio seguente viene definita una matrice di Tuple<T1,T2,T3,T4,T5> oggetti che contengono i nomi dei runback nel football americano, il numero di partite in cui hanno giocato e il numero di passaggi, i yard totali ottenuti e i touchdown segnati durante tali partite. La matrice viene passata al metodo , che calcola il numero di porta in esecuzione per gioco, i yard medi per partita, i
ComputeStatisticsyard medi per trasporto e il numero medio di touchdown per tentativo.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.035open 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.035Imports 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.035Per restituire più valori da un metodo senza l'uso di
outparametri (in C#) oByRefparametri (in Visual Basic). Ad esempio, l'esempio precedente restituisce le statistiche calcolate, insieme al nome del giocatore, in una matrice di Tuple<T1,T2,T3,T4,T5> oggetti.Per passare più valori a un metodo tramite un singolo parametro. Ad esempio, il Thread.Start(Object) metodo ha un singolo parametro che consente di fornire un valore al metodo eseguito dal thread all'avvio. Se si specifica un Tuple<T1,T2,T3,T4,T5> oggetto come argomento del metodo, è possibile fornire la routine di avvio del thread con cinque elementi di dati.
Costruttori
| Nome | Descrizione |
|---|---|
| Tuple<T1,T2,T3,T4,T5>(T1, T2, T3, T4, T5) |
Inizializza una nuova istanza della classe Tuple<T1,T2,T3,T4,T5>. |
Proprietà
| Nome | Descrizione |
|---|---|
| Item1 |
Ottiene il valore del primo componente dell'oggetto corrente Tuple<T1,T2,T3,T4,T5> . |
| Item2 |
Ottiene il valore del secondo componente dell'oggetto corrente Tuple<T1,T2,T3,T4,T5> . |
| Item3 |
Ottiene il valore del terzo componente dell'oggetto corrente Tuple<T1,T2,T3,T4,T5> . |
| Item4 |
Ottiene il valore del quarto componente dell'oggetto corrente Tuple<T1,T2,T3,T4,T5> . |
| Item5 |
Ottiene il valore del quinto componente dell'oggetto corrente Tuple<T1,T2,T3,T4,T5> . |
Metodi
| Nome | Descrizione |
|---|---|
| Equals(Object) |
Restituisce un valore che indica se l'oggetto corrente Tuple<T1,T2,T3,T4,T5> è uguale a un oggetto specificato. |
| GetHashCode() |
Restituisce il codice hash per l'oggetto corrente Tuple<T1,T2,T3,T4,T5> . |
| GetType() |
Ottiene il Type dell'istanza corrente. (Ereditato da Object) |
| MemberwiseClone() |
Crea una copia superficiale del Objectcorrente. (Ereditato da Object) |
| ToString() |
Restituisce una stringa che rappresenta il valore di questa Tuple<T1,T2,T3,T4,T5> istanza. |
Implementazioni dell'interfaccia esplicita
| Nome | Descrizione |
|---|---|
| IComparable.CompareTo(Object) |
Confronta l'oggetto corrente Tuple<T1,T2,T3,T4,T5> con un oggetto specificato e restituisce un numero intero che indica se l'oggetto corrente è precedente, successivo o nella stessa posizione dell'oggetto specificato nell'ordinamento. |
| IStructuralComparable.CompareTo(Object, IComparer) |
Confronta l'oggetto corrente Tuple<T1,T2,T3,T4,T5> con un oggetto specificato utilizzando un operatore di confronto specificato e restituisce un intero che indica se l'oggetto corrente è precedente, successivo o nella stessa posizione dell'oggetto specificato nell'ordinamento. |
| IStructuralEquatable.Equals(Object, IEqualityComparer) |
Restituisce un valore che indica se l'oggetto corrente Tuple<T1,T2,T3,T4,T5> è uguale a un oggetto specificato in base a un metodo di confronto specificato. |
| IStructuralEquatable.GetHashCode(IEqualityComparer) |
Calcola il codice hash per l'oggetto corrente Tuple<T1,T2,T3,T4,T5> utilizzando un metodo di calcolo specificato. |
| ITuple.Item[Int32] |
Ottiene il valore dell'elemento specificato |
| ITuple.Length |
Ottiene il numero di elementi nell'oggetto |
Metodi di estensione
| Nome | Descrizione |
|---|---|
| Deconstruct<T1,T2,T3,T4,T5>(Tuple<T1,T2,T3,T4,T5>, T1, T2, T3, T4, T5) |
Decostruisce una tupla con 5 elementi in variabili separate. |
| ToValueTuple<T1,T2,T3,T4,T5>(Tuple<T1,T2,T3,T4,T5>) |
Converte un'istanza della |