Tuple<T1,T2,T3,T4,T5,T6,T7>.Equals(Object) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
回傳一個值,表示目前 Tuple<T1,T2,T3,T4,T5,T6,T7> 物件是否等於指定物件。
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
範例
以下範例定義了包含1950年至2000年間洛杉磯與紐約人口資料的六重組陣列。 每個七聯體的第一個組成部分代表該城市。 第一、第三和第四七組包含紐約的資料。 第一七連音是第四七連音的重複。 第三個七連體將城市標示為「紐約市」而非「紐約」。 如範例所示,只有第四個七元組等於第一個七元組。
using System;
public class Example
{
public static void Main()
{
// Get population data for New York City and Los Angeles, 1960-2000.
Tuple<string, int, int, int, int, int, int>[] urbanPopulations =
{ Tuple.Create("New York", 7891957, 7781984, 7894862, 7071639, 7322564, 8008278),
Tuple.Create("Los Angeles", 1970358, 2479015, 2816061, 2966850, 3485398, 3694820),
Tuple.Create("New York City", 7891957, 7781984, 7894862, 7071639, 7322564, 8008278),
Tuple.Create("New York", 7891957, 7781984, 7894862, 7071639, 7322564, 8008278) };
// Compare each tuple with every other tuple for equality.
for (int ctr = 0; ctr <= urbanPopulations.Length - 2; ctr++)
{
var urbanPopulation = urbanPopulations[ctr];
Console.WriteLine(urbanPopulation.ToString() + " = ");
for (int innerCtr = ctr +1; innerCtr <= urbanPopulations.Length - 1; innerCtr++)
Console.WriteLine(" {0}: {1}", urbanPopulations[innerCtr],
urbanPopulation.Equals(urbanPopulations[innerCtr]));
Console.WriteLine();
}
}
}
// The example displays the following output:
// (New York, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278) =
// (Los Angeles, 1970358, 2479015, 2816061, 2966850, 3485398, 3694820): False
// (New York City, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278): False
// (New York, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278): True
//
// (Los Angeles, 1970358, 2479015, 2816061, 2966850, 3485398, 3694820) =
// (New York City, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278): False
// (New York, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278): False
//
// (New York City, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278) =
// (New York, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278): False
open System
// Get population data for New York City and Los Angeles, 1960-2000.
let urbanPopulations =
[| Tuple.Create("New York", 7891957, 7781984, 7894862, 7071639, 7322564, 8008278)
Tuple.Create("Los Angeles", 1970358, 2479015, 2816061, 2966850, 3485398, 3694820)
Tuple.Create("New York City", 7891957, 7781984, 7894862, 7071639, 7322564, 8008278)
Tuple.Create("New York", 7891957, 7781984, 7894862, 7071639, 7322564, 8008278) |]
// Compare each tuple with every other tuple for equality.
for ctr = 0 to urbanPopulations.Length - 2 do
let urbanPopulation = urbanPopulations[ctr]
printfn $"{urbanPopulation} = "
for innerCtr = ctr + 1 to urbanPopulations.Length - 1 do
printfn $" {urbanPopulations[innerCtr]}: {urbanPopulation.Equals urbanPopulations[innerCtr]}"
printfn ""
// The example displays the following output:
// (New York, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278) =
// (Los Angeles, 1970358, 2479015, 2816061, 2966850, 3485398, 3694820): False
// (New York City, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278): False
// (New York, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278): True
//
// (Los Angeles, 1970358, 2479015, 2816061, 2966850, 3485398, 3694820) =
// (New York City, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278): False
// (New York, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278): False
//
// (New York City, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278) =
// (New York, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278): False
Module Example
Public Sub Main()
' Get population data for New York City and Los Angeles, 1960-2000.
Dim urbanPopulations() =
{ Tuple.Create("New York", 7891957, 7781984, 7894862,
7071639, 7322564, 8008278),
Tuple.Create("Los Angeles", 1970358, 2479015, 2816061,
2966850, 3485398, 3694820),
Tuple.Create("New York City", 7891957, 7781984, 7894862,
7071639, 7322564, 8008278),
Tuple.Create("New York", 7891957, 7781984, 7894862,
7071639, 7322564, 8008278) }
' Compare each tuple with every other tuple for equality.
For ctr As Integer = 0 To urbanPopulations.Length - 2
Dim urbanPopulation = urbanPopulations(ctr)
Console.WriteLine(urbanPopulation.ToString() + " = ")
For innerCtr As Integer = ctr + 1 To urbanPopulations.Length - 1
Console.WriteLine(" {0}: {1}", urbanPopulations(innerCtr), _
urbanPopulation.Equals(urbanPopulations(innerCtr)))
Next
Console.WriteLine()
Next
End Sub
End Module
' The example displays the following output:
' (New York, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278) =
' (Los Angeles, 1970358, 2479015, 2816061, 2966850, 3485398, 3694820): False
' (New York City, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278): False
' (New York, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278): True
'
' (Los Angeles, 1970358, 2479015, 2816061, 2966850, 3485398, 3694820) =
' (New York City, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278): False
' (New York, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278): False
'
' (New York City, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278) =
' (New York, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278): False
備註
在以下條件下,參數 obj 被視為等於當前實例:
它是一個 Tuple<T1,T2,T3,T4,T5,T6,T7> 物件。
它的七個組成部分與目前的實例類型相同。
其七個組成部分與當前實例相同。 等號由每個元件的預設物件等式比較器決定。