setA と setB の 2 つの HashSet があります。
- setA と setB の補数をどのように見つけることができますか?
- 交差点のコードは、交差点を見つけるための最良の方法ですか?
コード
string stringA = "A,B,A,A";
string stringB = "C,A,B,D";
HashSet<string> setA = new HashSet<string>(stringA.Split(',').Select(t => t.Trim()));
HashSet<string> setB = new HashSet<string>(stringB.Split(',').Select(t => t.Trim()));
//Intersection - Present in A and B
HashSet<string> intersectedSet = new HashSet<string>( setA.Intersect(setB));
//Complemenet - Present in A; but not present in B
更新:
OrdianlIgnoreCase
大文字 と小文字を区別しないモードで HashSet<string>.Contains() メソッドを使用する方法
参考: