StringDictionaryにC#の特定の値が含まれているかどうかを確認します
StringDictionaryに特定の値が含まれているかどうかを確認するためのコードは、次のとおりです-
例
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main(){
StringDictionary strDict1 = new StringDictionary();
strDict1.Add("A", "John");
strDict1.Add("B", "Andy");
strDict1.Add("C", "Tim");
strDict1.Add("D", "Ryan");
strDict1.Add("E", "Kevin");
strDict1.Add("F", "Katie");
strDict1.Add("G", "Brad");
Console.WriteLine("StringDictionary1 elements...");
foreach(DictionaryEntry d in strDict1){
Console.WriteLine(d.Key + " " + d.Value);
}
Console.WriteLine("Does StringDictionary1 has key G? "+strDict1.ContainsKey("G"));
Console.WriteLine("Does StringDictionary1 has value Ryan? "+strDict1.ContainsValue("Ryan"));
StringDictionary strDict2 = new StringDictionary();
strDict2.Add("A", "John");
strDict2.Add("B", "Andy");
strDict2.Add("C", "Tim");
strDict2.Add("D", "Ryan");
strDict2.Add("E", "Kevin");
strDict2.Add("F", "Katie");
strDict2.Add("G", "Brad");
Console.WriteLine("\nStringDictionary2 elements...");
foreach(DictionaryEntry d in strDict2){
Console.WriteLine(d.Key + " " + d.Value);
}
Console.WriteLine("\nIs Dictionary2 equal to Dictionary1? = "+strDict2.Equals(strDict1));
Console.WriteLine("Does StringDictionary2 has key B? "+strDict2.ContainsKey("B"));
}
} 出力
これにより、次の出力が生成されます-
StringDictionary1 elements... a John b Andy c Tim d Ryan e Kevin f Katie g Brad Does StringDictionary1 has key G? True Does StringDictionary1 has value Ryan? True StringDictionary2 elements... a John b Andy c Tim d Ryan e Kevin f Katie g Brad Is Dictionary2 equal to Dictionary1? = False Does StringDictionary2 has key B? True
例
別の例を見てみましょう-
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main(){
StringDictionary strDict1 = new StringDictionary();
strDict1.Add("U", "Electronics");
strDict1.Add("V", "Toys");
strDict1.Add("W", "Books");
strDict1.Add("X", "Accessories");
Console.WriteLine("StringDictionary1 elements...");
foreach(DictionaryEntry d in strDict1){
Console.WriteLine(d.Key + " " + d.Value);
}
Console.WriteLine("Does StringDictionary1 has key G? "+strDict1.ContainsKey("G"));
Console.WriteLine("Does StringDictionary1 has value Footwear? "+strDict1.ContainsValue("Footwear"));
StringDictionary strDict2 = new StringDictionary();
strDict2.Add("A", "John");
strDict2.Add("B", "Andy");
strDict2.Add("C", "Tim");
strDict2.Add("D", "Ryan");
strDict2.Add("E", "Kevin");
strDict2.Add("F", "Katie");
strDict2.Add("G", "Brad");
Console.WriteLine("\nStringDictionary2 elements...");
foreach(DictionaryEntry d in strDict2){
Console.WriteLine(d.Key + " " + d.Value);
}
Console.WriteLine("\nIs Dictionary2 equal to Dictionary1? = "+strDict2.Equals(strDict1));
Console.WriteLine("Does StringDictionary2 has key B? "+strDict2.ContainsKey("B"));
}
} 出力
これにより、次の出力が生成されます-
StringDictionary1 elements... x Accessories u Electronics v Toys w Books Does StringDictionary1 has key G? False Does StringDictionary1 has value Footwear? False StringDictionary2 elements... a John b Andy c Tim d Ryan e Kevin f Katie g Brad Is Dictionary2 equal to Dictionary1? = False Does StringDictionary2 has key B? True
-
HashSetにC#で指定された要素が含まれているかどうかを確認します
HashSetに指定された要素が含まれているかどうかを確認するためのコードは、次のとおりです- 例 using System; using System.Collections.Generic; public class Demo { public static void Main(){ HashSet<int> set1 = new HashSet<int>(); set1.Add(25); set1.Add(50);
-
配列に指定された値が含まれているかどうかを確認するJavaプログラム
この記事では、配列に指定された値が含まれているかどうかを確認する方法を理解します。これは、配列要素を反復処理し、指定された入力を配列要素と比較することで実現されます。 以下は同じのデモンストレーションです- 入力 入力が-であると仮定します Enter the number to be searched: 25 The elements in the integer array: 15 20 25 30 35 出力 必要な出力は-になります The array contains the given value アルゴリズム Step 1 - START Step 2 -&nbs