C#のDictionary.ContainsKey()メソッド
C#のDictionary.ContainsKey()メソッドは、Dictionary
構文
public bool ContainsKey (TKey key);
上記では、パラメータキーが検出されるキーです。
ここで、Dictionary.ContainsKey()メソッドを実装する例を見てみましょう-
例
using System; using System.Collections.Generic; public class Demo { public static void Main(){ Dictionary<string, string> dict = new Dictionary<string, string>(); dict.Add("One", "John"); dict.Add("Two", "Tom"); dict.Add("Three", "Jacob"); dict.Add("Four", "Kevin"); dict.Add("Five", "Nathan"); Console.WriteLine("Count of elements = "+dict.Count); Console.WriteLine("\nKey/value pairs..."); foreach(KeyValuePair<string, string> res in dict){ Console.WriteLine("Key = {0}, Value = {1}", res.Key, res.Value); } if (dict.ContainsKey("Three")) Console.WriteLine("Key found!"); else Console.WriteLine("Key isn't in the dictionary!"); dict.Clear(); Console.WriteLine("Cleared Key/value pairs..."); foreach(KeyValuePair<string, string> res in dict){ Console.WriteLine("Key = {0}, Value = {1}", res.Key, res.Value); } Console.WriteLine("Count of elements now = "+dict.Count); } }
出力
これにより、次の出力が生成されます-
Count of elements = 5 Key/value pairs... Key = One, Value = John Key = Two, Value = Tom Key = Three, Value = Jacob Key = Four, Value = Kevin Key = Five, Value = Nathan Key found! Cleared Key/value pairs... Count of elements now = 0
辞書を実装する別の例を見てみましょう。 containsKeyプロパティ-
例
using System; using System.Collections.Generic; public class Demo { public static void Main(){ Dictionary<string, string> dict = new Dictionary<string, string>(); dict.Add("One", "John"); dict.Add("Two", "Tom"); dict.Add("Three", "Jacob"); dict.Add("Four", "Kevin"); dict.Add("Five", "Nathan"); Console.WriteLine("Count of elements = "+dict.Count); Console.WriteLine("\nKey/value pairs..."); foreach(KeyValuePair<string, string> res in dict){ Console.WriteLine("Key = {0}, Value = {1}", res.Key, res.Value); } if (dict.ContainsKey("mykey")) Console.WriteLine("Key found!"); else Console.WriteLine("Key isn't in the dictionary!"); dict.Clear(); Console.WriteLine("Cleared Key/value pairs..."); foreach(KeyValuePair<string, string> res in dict){ Console.WriteLine("Key = {0}, Value = {1}", res.Key, res.Value); } Console.WriteLine("Count of elements now = "+dict.Count); } }
出力
これにより、次の出力が生成されます-
Count of elements = 5 Key/value pairs... Key = One, Value = John Key = Two, Value = Tom Key = Three, Value = Jacob Key = Four, Value = Kevin Key = Five, Value = Nathan Key isn't in the dictionary! Cleared Key/value pairs... Count of elements now = 0
-
Node.jsのcrypto.generateKeyPair()メソッド
crypto.generateKeyPair()を使用して、指定されたタイプの新しい非対称キーペアを生成できます。キーペアを生成するためにサポートされているタイプは、RSA、DSA、EC、Ed25519、Ed448、X25519、X448、およびDHです。この関数は、publicKeyEncodingまたはprivateKeyEncodingが指定されている場合、その結果に対してkeyObject.exportが呼び出されたかのように動作します。指定されていない場合、keyObjectのそれぞれの部分が返されます。 構文 crypto.generateKeyPair(type, options
-
HTML DOM Storage key()メソッド
HTML DOM Storage key()メソッドは、ストレージオブジェクト内の特定のインデックスにあるキー名を返すために使用されます。インデックスはパラメータとしてkey()メソッドに渡されます。ストレージオブジェクトは、セッションオブジェクトまたはlocalStorageオブジェクトにすることができます。 構文 以下は、-の構文です。 localStorageを使用したStoragekey()メソッド- localStorage.key(index); sessionStorageを使用したStoragekey()メソッド- sessionStorage.key(index);