C#SortedDictionary.Add()メソッド
C#のSortedDictionary.Add()メソッドは、指定されたキーと値を持つ要素をSortedDictionary
構文
構文は次のとおりです-
public void Add (TKey key, TValue val);
上記では、value keyは追加する要素のキーであり、valは追加する要素の値です。
例
例を見てみましょう-
using System;
using System.Collections;
using System.Collections.Generic;
public class Demo {
public static void Main(){
SortedDictionary<int, string> sortedDict = new SortedDictionary<int, string>();
sortedDict.Add(100, "Mobile");
sortedDict.Add(200, "Laptop");
sortedDict.Add(300, "Desktop");
sortedDict.Add(400, "Speakers");
sortedDict.Add(500, "Headphone");
sortedDict.Add(600, "Earphone");
Console.WriteLine("SortedDictionary key-value pairs...");
IDictionaryEnumerator demoEnum = sortedDict.GetEnumerator();
while (demoEnum.MoveNext())
Console.WriteLine("Key = " + demoEnum.Key + ", Value = " + demoEnum.Value);
}
} 出力
これにより、次の出力が生成されます-
SortedDictionary key-value pairs... Key = 100, Value = Mobile Key = 200, Value = Laptop Key = 300, Value = Desktop Key = 400, Value = Speakers Key = 500, Value = Headphone Key = 600, Value = Earphone
例
別の例を見てみましょう-
using System;
using System.Collections;
using System.Collections.Generic;
public class Demo {
public static void Main(){
SortedDictionary<string, string> sortedDict = new SortedDictionary<string, string>();
sortedDict.Add("A", "John");
sortedDict.Add("B", "Andy");
sortedDict.Add("C", "Tim");
sortedDict.Add("D", "Ryan");
sortedDict.Add("E", "Kevin");
sortedDict.Add("F", "Katie");
sortedDict.Add("G", "Brad");
Console.WriteLine("SortedDictionary key-value pairs...");
IDictionaryEnumerator demoEnum = sortedDict.GetEnumerator();
while (demoEnum.MoveNext())
Console.WriteLine("Key = " + demoEnum.Key + ", Value = " + demoEnum.Value);
Console.WriteLine("\nThe SortedDictionary has the key F? = "+sortedDict.ContainsKey("F"));
}
} 出力
これにより、次の出力が生成されます-
SortedDictionary key-value pairs... Key = A, Value = John Key = B, Value = Andy Key = C, Value = Tim Key = D, Value = Ryan Key = E, Value = Kevin Key = F, Value = Katie Key = G, Value = Brad The SortedDictionary has the key F? = True
-
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 insertBefore()メソッド
HTML DOMのinsertBefore()メソッドは、既存の子ノードの前に新しいノードを挿入します。 構文 以下は構文です- positionStringおよびtextのパラメーターを使用してinsertBefore()を呼び出す node.insertBefore(newNode, existingNode) ここでは、パラメータ 次のようになります- パラメータ パラメータ 説明 newNode 最初に追加されるのは新しく作成された子ノードです 既存のノード これは既存のノードです 例 InsertBefore()の例を見てみましょう メソッド-