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
。
範例
下列範例會定義 5 Tuple 物件的陣列,其中包含兩個測試群組中病患溫度的相關資料。 陣列的第一個元件會提供測試群組的數目,而第二個到第五個元件會以每小時間隔提供病患的溫度。 系統會 Tuple<T1,T2,T3,T4,T5>.Equals(Object) 呼叫 方法,以比較每個 Tuple<T1,T2,T3,T4,T5> 物件與其他 Tuple<T1,T2,T3,T4,T5> 物件。 輸出說明 Equals 只有在物件的所有五個元件 Tuple<T1,T2,T3,T4,T5> 都有相等值時,方法才會傳回 true
。
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>它是 物件。
其五個元件的類型與目前的實例相同。
其五個元件等於目前實例的元件。 是否相等由每個元件的預設物件相等比較子決定。