2つのHashSetオブジェクトがC#で等しいかどうかを確認します
2つのHashSetオブジェクトが等しいかどうかを確認するためのコードは、次のとおりです-
例
using System;
using System.Collections.Generic;
public class Demo {
public static void Main(String[] args) {
HashSet<string> set1 = new HashSet<string>();
set1.Add("A");
set1.Add("B");
set1.Add("C");
set1.Add("D");
set1.Add("E");
set1.Add("F");
set1.Add("G");
set1.Add("H");
Console.WriteLine("Elements in HashSet1...");
foreach (string res in set1) {
Console.WriteLine(res);
}
HashSet<string> set2 = new HashSet<string>();
set2.Add("John");
set2.Add("Jacob");
set2.Add("Ryan");
set2.Add("Tom");
set2.Add("Andy");
set2.Add("Tim");
set2.Add("Steve");
set2.Add("Mark");
Console.WriteLine("Elements in HashSet2...");
foreach (string res in set2) {
Console.WriteLine(res);
}
HashSet<string> set3 = new HashSet<string>();
set3 = set2;
Console.WriteLine("Is HashSet3 equal to HashSet2? = "+set3.Equals(set2));
}
} 出力
これにより、次の出力が生成されます-
Elements in HashSet1... A B C D E F G H Elements in HashSet2... John Jacob Ryan Tom Andy Tim Steve Mark Is HashSet3 equal to HashSet2? = True
例
別の例を見てみましょう-
using System;
using System.Collections.Generic;
public class Demo {
public static void Main(String[] args){
HashSet<string> set1 = new HashSet<string>();
set1.Add("A");
set1.Add("B");
set1.Add("C");
set1.Add("D");
set1.Add("E");
set1.Add("F");
set1.Add("G");
set1.Add("H");
Console.WriteLine("Elements in HashSet1...");
foreach (string res in set1){
Console.WriteLine(res);
}
HashSet<string> set2 = new HashSet<string>();
set2.Add("John");
set2.Add("Jacob");
set2.Add("Ryan");
set2.Add("Tom");
set2.Add("Andy");
set2.Add("Tim");
set2.Add("Steve");
set2.Add("Mark");
Console.WriteLine("Elements in HashSet2...");
foreach (string res in set2){
Console.WriteLine(res);
}
Console.WriteLine("Is HashSet2 equal to HashSet1? = "+set2.Equals(set1));
}
} 出力
これにより、次の出力が生成されます-
Elements in HashSet1... A B C D E F G H Elements in HashSet2... John Jacob Ryan Tom Andy Tim Steve Mark Is HashSet2 equal to HashSet1? = False
-
PythonPandas-2つのIndexオブジェクトが等しいかどうかを判断します
2つのIndexオブジェクトが等しいかどうかを判断するには、 equals()を使用します メソッド。 まず、必要なライブラリをインポートします- import pandas as pd index1とindex2の作成- index1 = pd.Index([15, 25, 55, 10, 100, 70, 35, 40, 55]) index2 = pd.Index([15, 25, 55, 10, 100, 70, 35, 40, 55]) index1とindex2を表示する- print("Pandas Index1...\n",index1) print(
-
PythonPandas-データフレームオブジェクトが等しいかどうかを確認します
DataFrameオブジェクトが等しいかどうかを確認するには、equals()メソッドを使用します。最初に、2つの列を持つDataFrame1を作成しましょう- dataFrame1 = pd.DataFrame( { "Car": ['BMW', 'Lexus', 'Audi', 'Mustang', 'Bentley', 'Jaguar'], "Reg_Price": [700