Tuple<T1,T2,T3> クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
3 タプルまたは 3 タプルを表します。
generic <typename T1, typename T2, typename T3>
public ref class Tuple : IComparable, System::Collections::IStructuralComparable, System::Collections::IStructuralEquatable
generic <typename T1, typename T2, typename T3>
public ref class Tuple : IComparable, System::Collections::IStructuralComparable, System::Collections::IStructuralEquatable, System::Runtime::CompilerServices::ITuple
public class Tuple<T1,T2,T3> : IComparable, System.Collections.IStructuralComparable, System.Collections.IStructuralEquatable
public class Tuple<T1,T2,T3> : IComparable, System.Collections.IStructuralComparable, System.Collections.IStructuralEquatable, System.Runtime.CompilerServices.ITuple
[System.Serializable]
public class Tuple<T1,T2,T3> : IComparable, System.Collections.IStructuralComparable, System.Collections.IStructuralEquatable
type Tuple<'T1, 'T2, 'T3> = class
interface IStructuralComparable
interface IStructuralEquatable
interface IComparable
type Tuple<'T1, 'T2, 'T3> = class
interface IStructuralComparable
interface IStructuralEquatable
interface IComparable
interface ITuple
[<System.Serializable>]
type Tuple<'T1, 'T2, 'T3> = class
interface IStructuralEquatable
interface IStructuralComparable
interface IComparable
[<System.Serializable>]
type Tuple<'T1, 'T2, 'T3> = class
interface IStructuralEquatable
interface IStructuralComparable
interface IComparable
interface ITuple
Public Class Tuple(Of T1, T2, T3)
Implements IComparable, IStructuralComparable, IStructuralEquatable
Public Class Tuple(Of T1, T2, T3)
Implements IComparable, IStructuralComparable, IStructuralEquatable, ITuple
型パラメーター
- T1
タプルの最初のコンポーネントの型。
- T2
タプルの 2 番目のコンポーネントの型。
- T3
タプルの 3 番目のコンポーネントの型。
- 継承
-
Tuple<T1,T2,T3>
- 属性
- 実装
注釈
タプルは、特定の数と値のシーケンスを持つデータ構造です。 Tuple<T1,T2,T3> クラスは 3 タプル (3 タプル) を表します。これは、3 つのコンポーネントを持つタプルです。
Tuple<T1,T2,T3> コンストラクターまたは静的Tuple<T1,T2,T3> メソッドを呼び出すことによって、Tuple.Create<T1,T2,T3>(T1, T2, T3) オブジェクトをインスタンス化できます。 タプルのコンポーネントの値は、読み取り専用の Item1、 Item2、および Item3 インスタンス のプロパティを使用して取得できます。
タプルは、一般的に次の 4 つの方法で使用されます。
1 つのデータ セットを表す。 たとえば、タプルはデータベース レコードを表し、そのコンポーネントはレコードの個々のフィールドを表すことができます。
データ セットへの簡単なアクセスと操作を提供します。 次の例では、学生の名前、その平均テスト スコア、および取得したテストの数を含む Tuple<T1,T2,T3> オブジェクトの配列を定義します。 配列は、テスト スコアの平均と標準偏差を計算する
ComputeStatisticsメソッドに渡されます。using System; public class Example { public static void Main() { Tuple<string, double, int>[] scores = { Tuple.Create("Jack", 78.8, 8), Tuple.Create("Abbey", 92.1, 9), Tuple.Create("Dave", 88.3, 9), Tuple.Create("Sam", 91.7, 8), Tuple.Create("Ed", 71.2, 5), Tuple.Create("Penelope", 82.9, 8), Tuple.Create("Linda", 99.0, 9), Tuple.Create("Judith", 84.3, 9) }; var result = ComputeStatistics(scores); Console.WriteLine("Mean score: {0:N2} (SD={1:N2}) (n={2})", result.Item2, result.Item3, result.Item1); } private static Tuple<int, double, double> ComputeStatistics(Tuple<string, double, int>[] scores) { int n = 0; double sum = 0; // Compute the mean. foreach (var score in scores) { n += score.Item3; sum += score.Item2 * score.Item3; } double mean = sum / n; // Compute the standard deviation. double ss = 0; foreach (var score in scores) { ss = Math.Pow(score.Item2 - mean, 2); } double sd = Math.Sqrt(ss/scores.Length); return Tuple.Create(scores.Length, mean, sd); } } // The example displays the following output: // Mean score: 87.02 (SD=0.96) (n=8)open System let computeStatistics (scores: Tuple<string, double, int>[]) = let mutable n = 0 let mutable sum = 0. // Compute the mean. for score in scores do n <- n + score.Item3 sum <- sum + score.Item2 * double score.Item3 let mean = sum / double n // Compute the standard deviation. let mutable ss = 0. for score in scores do ss <- (score.Item2 - mean) ** 2. let sd = sqrt (ss / double scores.Length) Tuple.Create(scores.Length, mean, sd) let scores = [| Tuple.Create("Jack", 78.8, 8) Tuple.Create("Abbey", 92.1, 9) Tuple.Create("Dave", 88.3, 9) Tuple.Create("Sam", 91.7, 8) Tuple.Create("Ed", 71.2, 5) Tuple.Create("Penelope", 82.9, 8) Tuple.Create("Linda", 99.0, 9) Tuple.Create("Judith", 84.3, 9) |] let result = computeStatistics scores printfn $"Mean score: {result.Item2:N2} (SD={result.Item3:N2}) (n={result.Item1})" // The example displays the following output: // Mean score: 87.02 (SD=0.96) (n=8)Module Example Public Sub Main() Dim scores() = { Tuple.Create("Jack", 78.8, 8), Tuple.Create("Abbey", 92.1, 9), Tuple.Create("Dave", 88.3, 9), Tuple.Create("Sam", 91.7, 8), Tuple.Create("Ed", 71.2, 5), Tuple.Create("Penelope", 82.9, 8), Tuple.Create("Linda", 99.0, 9), Tuple.Create("Judith", 84.3, 9) } Dim result = ComputeStatistics(scores) Console.WriteLine("Mean score: {0:N2} (SD={1:N2}) (n={2})", result.Item2, result.Item3, result.Item1) End Sub Private Function ComputeStatistics(scores() As Tuple(Of String, Double, Integer)) _ As Tuple(Of Integer, Double, Double) Dim n As Integer = 0 Dim sum As Double = 0 ' Compute the mean. For Each score In scores n+= score.Item3 sum += score.Item2 * score.Item3 Next Dim mean As Double = sum / n ' Compute the standard deviation. Dim ss As Double = 0 For Each score In scores ss = Math.Pow(score.Item2 - mean, 2) Next Dim sd As Double = Math.Sqrt(ss/scores.Length) Return Tuple.Create(scores.Length, mean, sd) End Function End Module ' The example displays the following output: ' Mean score: 87.02 (SD=0.96) (n=8)outパラメーター (C#) またはByRefパラメーター (Visual Basic) を使用せずに、メソッドから複数の値を返す場合。 たとえば、前の例では、 Tuple<T1,T2,T3> オブジェクトのサマリー テスト スコア統計が返されます。1 つのパラメーターを使用して複数の値をメソッドに渡す。 たとえば、 Thread.Start(Object) メソッドには、起動時にスレッドが実行するメソッドに 1 つの値を指定できる 1 つのパラメーターがあります。 メソッド引数として Tuple<T1,T2,T3> オブジェクトを指定する場合は、スレッドのスタートアップ ルーチンに 3 つのデータ項目を指定できます。
コンストラクター
| 名前 | 説明 |
|---|---|
| Tuple<T1,T2,T3>(T1, T2, T3) |
Tuple<T1,T2,T3> クラスの新しいインスタンスを初期化します。 |
プロパティ
| 名前 | 説明 |
|---|---|
| Item1 |
現在の Tuple<T1,T2,T3> オブジェクトの最初のコンポーネントの値を取得します。 |
| Item2 |
現在の Tuple<T1,T2,T3> オブジェクトの 2 番目のコンポーネントの値を取得します。 |
| Item3 |
現在の Tuple<T1,T2,T3> オブジェクトの 3 番目のコンポーネントの値を取得します。 |
メソッド
| 名前 | 説明 |
|---|---|
| Equals(Object) |
現在の Tuple<T1,T2,T3> オブジェクトが指定したオブジェクトと等しいかどうかを示す値を返します。 |
| GetHashCode() |
現在の Tuple<T1,T2,T3> オブジェクトのハッシュ コードを返します。 |
| GetType() |
現在のインスタンスの Type を取得します。 (継承元 Object) |
| MemberwiseClone() |
現在の Objectの簡易コピーを作成します。 (継承元 Object) |
| ToString() |
この Tuple<T1,T2,T3> インスタンスの値を表す文字列を返します。 |
明示的なインターフェイスの実装
| 名前 | 説明 |
|---|---|
| IComparable.CompareTo(Object) |
現在の Tuple<T1,T2,T3> オブジェクトを指定したオブジェクトと比較し、現在のオブジェクトが並べ替え順序で指定したオブジェクトの前、後、または同じ位置にあるかどうかを示す整数を返します。 |
| IStructuralComparable.CompareTo(Object, IComparer) |
指定した比較子を使用して、現在の Tuple<T1,T2,T3> オブジェクトを指定したオブジェクトと比較し、現在のオブジェクトが並べ替え順序で指定したオブジェクトの前、後、または同じ位置にあるかどうかを示す整数を返します。 |
| IStructuralEquatable.Equals(Object, IEqualityComparer) |
現在の Tuple<T1,T2,T3> オブジェクトが、指定した比較メソッドに基づいて、指定したオブジェクトと等しいかどうかを示す値を返します。 |
| IStructuralEquatable.GetHashCode(IEqualityComparer) |
指定した計算方法を使用して、現在の Tuple<T1,T2,T3> オブジェクトのハッシュ コードを計算します。 |
| ITuple.Item[Int32] |
指定した |
| ITuple.Length |
|
拡張メソッド
| 名前 | 説明 |
|---|---|
| Deconstruct<T1,T2,T3>(Tuple<T1,T2,T3>, T1, T2, T3) |
3 つの要素を持つタプルを個別の変数に分解します。 |
| ToValueTuple<T1,T2,T3>(Tuple<T1,T2,T3>) |
|