Hashtable类表示键和值对的集合,这些键和值对是根据键的哈希码进行组织的。该键用于访问集合中的项目。
句法:
myTable1.Equals(myTable2)
在这里, myTable1和myTable2是要检查的两个哈希表。
下面给出了一些示例,以更好地理解实现:
范例1:
// C# code to check if a Hashtable is
// equal to other Hashtable or not
using System;
using System.Collections;
class GFG {
// Driver code
public static void Main()
{
// Creating a Hashtable
Hashtable myTable = new Hashtable();
// Adding elements in Hashtable
myTable.Add("g", "geeks");
myTable.Add("c", "c++");
myTable.Add("d", "data structures");
myTable.Add("q", "quiz");
// check if myTable is equal to myTable or not
Console.WriteLine(myTable.Equals(myTable));
}
}
输出:
True
范例2:
// C# code to check if a Hashtable is
// equal to other Hashtable or not
using System;
using System.Collections;
class GFG {
// Driver code
public static void Main()
{
// Creating 1st Hashtable
Hashtable myTable1 = new Hashtable();
// Adding elements in Hashtable
myTable1.Add("g", "geeks");
myTable1.Add("c", "c++");
myTable1.Add("d", "data structures");
myTable1.Add("q", "quiz");
// Creating 2nd Hashtable
Hashtable myTable2 = new Hashtable();
// Adding elements in Hashtable
myTable2.Add("G", "geeksforgeeks");
myTable2.Add("C", "C#");
myTable2.Add("d", "data structures");
myTable2.Add("q", "quiz");
// check if both the Hashtables
// are equal or not
Console.WriteLine(myTable1.Equals(myTable2));
}
}
输出:
False