Tuple<T1,T2,T3,T4,T5>.Equals(Object) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
回傳一個值,表示目前 Tuple<T1,T2,T3,T4,T5> 物件是否等於指定物件。
public:
override bool Equals(System::Object ^ obj);
public override bool Equals(object obj);
public override bool Equals(object? obj);
override this.Equals : obj -> bool
Public Overrides Function Equals (obj As Object) As Boolean
參數
- obj
- Object
這個例子是要比較的對象。
傳回
true如果當前實例等於指定的物件;否則,。 false
範例
以下範例定義了一個包含兩個測試組患者體溫資料的五元組物件陣列。 陣列的第一部分提供測試組的數量,第二至第五部分則每小時提供病人的體溫。
Tuple<T1,T2,T3,T4,T5>.Equals(Object)此方法被呼叫用來將每個Tuple<T1,T2,T3,T4,T5>物件與其他物件Tuple<T1,T2,T3,T4,T5>進行比較。 輸出說明Equals該方法只有在物件的true五個成分值相等時才會回傳Tuple<T1,T2,T3,T4,T5>。
using System;
public class Class1
{
public static void Main()
{
Tuple<int, double, double, double, double>[] temperatureInfos =
{ Tuple.Create(2, 97.9, 97.8, 98.0, 98.2),
Tuple.Create(1, 98.6, 98.8, 98.8, 99.0),
Tuple.Create(2, 98.6, 98.6, 98.6, 98.4),
Tuple.Create(1, 98.4, 98.6, 99.0, 99.2),
Tuple.Create(2, 98.6, 98.6, 98.6, 98.4),
Tuple.Create(1, 98.6, 98.8, 98.8, 99.0) };
// Compare each item with every other item for equality.
for (int ctr = 0; ctr < temperatureInfos.Length; ctr++)
{
var temperatureInfo = temperatureInfos[ctr];
for (int ctr2 = ctr + 1; ctr2 < temperatureInfos.Length; ctr2++)
Console.WriteLine("{0} = {1}: {2}", temperatureInfo, temperatureInfos[ctr2],
temperatureInfo.Equals(temperatureInfos[ctr2]));
Console.WriteLine();
}
}
}
// The example displays the following output:
// (2, 97.9, 97.8, 98, 98.2) = (1, 98.6, 98.8, 98.8, 99): False
// (2, 97.9, 97.8, 98, 98.2) = (2, 98.6, 98.6, 98.6, 98.4): False
// (2, 97.9, 97.8, 98, 98.2) = (1, 98.4, 98.6, 99, 99.2): False
// (2, 97.9, 97.8, 98, 98.2) = (2, 98.6, 98.6, 98.6, 98.4): False
// (2, 97.9, 97.8, 98, 98.2) = (1, 98.6, 98.8, 98.8, 99): False
//
// (1, 98.6, 98.8, 98.8, 99) = (2, 98.6, 98.6, 98.6, 98.4): False
// (1, 98.6, 98.8, 98.8, 99) = (1, 98.4, 98.6, 99, 99.2): False
// (1, 98.6, 98.8, 98.8, 99) = (2, 98.6, 98.6, 98.6, 98.4): False
// (1, 98.6, 98.8, 98.8, 99) = (1, 98.6, 98.8, 98.8, 99): True
//
// (2, 98.6, 98.6, 98.6, 98.4) = (1, 98.4, 98.6, 99, 99.2): False
// (2, 98.6, 98.6, 98.6, 98.4) = (2, 98.6, 98.6, 98.6, 98.4): True
// (2, 98.6, 98.6, 98.6, 98.4) = (1, 98.6, 98.8, 98.8, 99): False
//
// (1, 98.4, 98.6, 99, 99.2) = (2, 98.6, 98.6, 98.6, 98.4): False
// (1, 98.4, 98.6, 99, 99.2) = (1, 98.6, 98.8, 98.8, 99): False
//
// (2, 98.6, 98.6, 98.6, 98.4) = (1, 98.6, 98.8, 98.8, 99): False
open System
let temperatureInfos =
[| Tuple.Create(2, 97.9, 97.8, 98.0, 98.2)
Tuple.Create(1, 98.6, 98.8, 98.8, 99.0)
Tuple.Create(2, 98.6, 98.6, 98.6, 98.4)
Tuple.Create(1, 98.4, 98.6, 99.0, 99.2)
Tuple.Create(2, 98.6, 98.6, 98.6, 98.4)
Tuple.Create(1, 98.6, 98.8, 98.8, 99.0) |]
// Compare each item with every other item for equality.
for ctr = 0 to temperatureInfos.Length - 1 do
let temperatureInfo = temperatureInfos[ctr]
for ctr2 = ctr + 1 to temperatureInfos.Length - 1 do
printfn $"{temperatureInfo} = {temperatureInfos[ctr2]}: {temperatureInfo.Equals temperatureInfos[ctr2]}"
printfn ""
// The example displays the following output:
// (2, 97.9, 97.8, 98, 98.2) = (1, 98.6, 98.8, 98.8, 99): False
// (2, 97.9, 97.8, 98, 98.2) = (2, 98.6, 98.6, 98.6, 98.4): False
// (2, 97.9, 97.8, 98, 98.2) = (1, 98.4, 98.6, 99, 99.2): False
// (2, 97.9, 97.8, 98, 98.2) = (2, 98.6, 98.6, 98.6, 98.4): False
// (2, 97.9, 97.8, 98, 98.2) = (1, 98.6, 98.8, 98.8, 99): False
//
// (1, 98.6, 98.8, 98.8, 99) = (2, 98.6, 98.6, 98.6, 98.4): False
// (1, 98.6, 98.8, 98.8, 99) = (1, 98.4, 98.6, 99, 99.2): False
// (1, 98.6, 98.8, 98.8, 99) = (2, 98.6, 98.6, 98.6, 98.4): False
// (1, 98.6, 98.8, 98.8, 99) = (1, 98.6, 98.8, 98.8, 99): True
//
// (2, 98.6, 98.6, 98.6, 98.4) = (1, 98.4, 98.6, 99, 99.2): False
// (2, 98.6, 98.6, 98.6, 98.4) = (2, 98.6, 98.6, 98.6, 98.4): True
// (2, 98.6, 98.6, 98.6, 98.4) = (1, 98.6, 98.8, 98.8, 99): False
//
// (1, 98.4, 98.6, 99, 99.2) = (2, 98.6, 98.6, 98.6, 98.4): False
// (1, 98.4, 98.6, 99, 99.2) = (1, 98.6, 98.8, 98.8, 99): False
//
// (2, 98.6, 98.6, 98.6, 98.4) = (1, 98.6, 98.8, 98.8, 99): False
Module Example
Public Sub Main()
Dim temperatureInfos() =
{ Tuple.Create(2, 97.9, 97.8, 98.0, 98.2),
Tuple.Create(1, 98.6, 98.8, 98.8, 99.0),
Tuple.Create(2, 98.6, 98.6, 98.6, 98.4),
Tuple.Create(1, 98.4, 98.6, 99.0, 99.2),
Tuple.Create(2, 98.6, 98.6, 98.6, 98.4),
Tuple.Create(1, 98.6, 98.8, 98.8, 99.0) }
' Compare each item with every other item for equality.
For ctr As Integer = 0 To temperatureInfos.Length - 1
Dim temperatureInfo = temperatureInfos(ctr)
For ctr2 As Integer = ctr + 1 To temperatureInfos.Length - 1
Console.WriteLine("{0} = {1}: {2}", temperatureInfo, temperatureInfos(ctr2),
temperatureInfo.Equals(temperatureInfos(ctr2)))
Next
Console.WriteLine()
Next
End Sub
End Module
' The example displays the following output:
' (2, 97.9, 97.8, 98, 98.2) = (1, 98.6, 98.8, 98.8, 99): False
' (2, 97.9, 97.8, 98, 98.2) = (2, 98.6, 98.6, 98.6, 98.4): False
' (2, 97.9, 97.8, 98, 98.2) = (1, 98.4, 98.6, 99, 99.2): False
' (2, 97.9, 97.8, 98, 98.2) = (2, 98.6, 98.6, 98.6, 98.4): False
' (2, 97.9, 97.8, 98, 98.2) = (1, 98.6, 98.8, 98.8, 99): False
'
' (1, 98.6, 98.8, 98.8, 99) = (2, 98.6, 98.6, 98.6, 98.4): False
' (1, 98.6, 98.8, 98.8, 99) = (1, 98.4, 98.6, 99, 99.2): False
' (1, 98.6, 98.8, 98.8, 99) = (2, 98.6, 98.6, 98.6, 98.4): False
' (1, 98.6, 98.8, 98.8, 99) = (1, 98.6, 98.8, 98.8, 99): True
'
' (2, 98.6, 98.6, 98.6, 98.4) = (1, 98.4, 98.6, 99, 99.2): False
' (2, 98.6, 98.6, 98.6, 98.4) = (2, 98.6, 98.6, 98.6, 98.4): True
' (2, 98.6, 98.6, 98.6, 98.4) = (1, 98.6, 98.8, 98.8, 99): False
'
' (1, 98.4, 98.6, 99, 99.2) = (2, 98.6, 98.6, 98.6, 98.4): False
' (1, 98.4, 98.6, 99, 99.2) = (1, 98.6, 98.8, 98.8, 99): False
'
' (2, 98.6, 98.6, 98.6, 98.4) = (1, 98.6, 98.8, 98.8, 99): False
備註
在以下條件下,參數 obj 被視為等於當前實例:
它是一個 Tuple<T1,T2,T3,T4,T5> 物件。
它的五個組成部分與目前實例類型相同。
其五個組成部分與當前實例相同。 等號由每個元件的預設物件等式比較器決定。