C#のHybridDictionaryクラス?
HybridDictionaryクラスは、コレクションが小さいときにListDictionaryを使用し、コレクションが大きくなるとハッシュテーブルに切り替えることでIDictionaryを実装します。
以下は、HybridDictionaryクラスのプロパティです-
| Sr.No | プロパティと説明 |
|---|---|
| 1 | カウント HybridDictionaryに含まれるキー/値のペアの数を取得します。 |
| 2 | IsFixedSize HybridDictionaryのサイズが固定されているかどうかを示す値を取得します。 |
| 3 | IsReadOnly HybridDictionaryが読み取り専用かどうかを示す値を取得します。 |
| 4 | IsSynchronized HybridDictionaryが同期されている(スレッドセーフ)かどうかを示す値を取得します。 |
| 5 | アイテム[オブジェクト] 指定されたキーに関連付けられた値を取得または設定します。 |
| 6 | キー HybridDictionaryのキーを含むICollectionを取得します。 |
| 7 | SyncRoot HybridDictionaryへのアクセスを同期するために使用できるオブジェクトを取得します。 |
| 8 | 値 HybridDictionaryの値を含むICollectionを取得します。 |
以下は、HybridDictionaryクラスのメソッドの一部です-
| Sr.No | メソッドと説明 |
|---|---|
| 1 | Add(Object、Object) 指定されたキーと値を持つエントリをHybridDictionaryに追加します。 |
| 2 | Clear() HybridDictionaryからすべてのエントリを削除します。 |
| 3 | contains(Object) HybridDictionaryに特定のキーが含まれているかどうかを判別します。p> |
| 4 | CopyTo(Array、Int32) HybridDictionaryエントリを指定されたインデックスのonedimensionArrayインスタンスにコピーします。 |
| 5 | Equals(Object) 指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判別します。(オブジェクトから継承) |
| 6 | GetEnumerator() HybridDictionaryを反復処理するIDictionaryEnumeratorを返します。 |
| 7 | GetHashCode() デフォルトのハッシュ関数として機能します。(オブジェクトから継承) |
| 8 | GetType() 現在のインスタンスのタイプを取得します。(オブジェクトから継承) |
HybridDictionaryでキーと値のペアの数をカウントするには、コードは次のとおりです-
例
いくつかの例を見てみましょう-
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
HybridDictionary dict1 = new HybridDictionary();
dict1.Add("A", "SUV");
dict1.Add("B", "MUV");
dict1.Add("C", "AUV");
Console.WriteLine("HybridDictionary1 elements...");
foreach(DictionaryEntry d in dict1) {
Console.WriteLine(d.Key + " " + d.Value);
}
Console.WriteLine("Count of Key/value pairs in Dictionary1 = "+dict1.Count);
HybridDictionary dict2 = new HybridDictionary();
dict2.Add("1", "One");
dict2.Add("2", "Two");
dict2.Add("3", "Three");
dict2.Add("4", "Four");
dict2.Add("5", "Five");
dict2.Add("6", "Six");
Console.WriteLine("\nHybridDictionary2 elements...");
foreach(DictionaryEntry d in dict2) {
Console.WriteLine(d.Key + " " + d.Value);
}
Console.WriteLine("Count of Key/value pairs in Dictionary2 = "+dict1.Count);
dict2.Clear();
Console.WriteLine("Count of Key/value pairs in Dictionary2 (Updated) = "+dict2.Count);
}
} 出力
これにより、次の出力が生成されます-
HybridDictionary1 elements... A SUV B MUV C AUV Count of Key/value pairs in Dictionary1 = 3 HybridDictionary2 elements... 1 One 2 Two 3 Three 4 Four 5 Five 6 Six Count of Key/value pairs in Dictionary2 = 3 Count of Key/value pairs in Dictionary2 (Updated) = 0
HybridDictionaryが同期されているかどうかを確認するためのコードは、次のとおりです-
例
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
HybridDictionary dict1 = new HybridDictionary();
dict1.Add("A", "Books");
dict1.Add("B", "Electronics");
dict1.Add("C", "Smart Wearables");
dict1.Add("D", "Pet Supplies");
dict1.Add("E", "Clothing");
dict1.Add("F", "Footwear");
Console.WriteLine("HybridDictionary1 elements...");
foreach(DictionaryEntry d in dict1) {
Console.WriteLine(d.Key + " " + d.Value);
}
Console.WriteLine("Is the HybridDictionary1 having fixed size? = "+dict1.IsFixedSize);
Console.WriteLine("If HybridDictionary1 read-only? = "+dict1.IsReadOnly);
Console.WriteLine("Is HybridDictionary1 synchronized = "+dict1.IsSynchronized);
HybridDictionary dict2 = new HybridDictionary();
dict2.Add("1", "One");
dict2.Add("2", "Two");
dict2.Add("3", "Three");
dict2.Add("4", "Four");
dict2.Add("5", "Five");
dict2.Add("6", "Six");
Console.WriteLine("\nHybridDictionary2 elements...");
foreach(DictionaryEntry d in dict2) {
Console.WriteLine(d.Key + " " + d.Value);
}
Console.WriteLine("Is HybridDictionary1 equal to HybridDictionary2? = "+(dict1.Equals(dict2)));
Console.WriteLine("Is the HybridDictionary2 having fixed size? = "+dict2.IsFixedSize);
Console.WriteLine("If HybridDictionary2 read-only? = "+dict2.IsReadOnly);
Console.WriteLine("Is HybridDictionary2 synchronized = "+dict2.IsSynchronized);
}
} 出力
これにより、次の出力が生成されます-
HybridDictionary1 elements... A Books B Electronics C Smart Wearables D Pet Supplies E Clothing F Footwear Is the HybridDictionary1 having fixed size? = False If HybridDictionary1 read-only? = False Is HybridDictionary1 synchronized = False HybridDictionary2 elements... 1 One 2 Two 3 Three 4 Four 5 Five 6 Six Is HybridDictionary1 equal to HybridDictionary2? = False Is the HybridDictionary2 having fixed size? = False If HybridDictionary2 read-only? = False Is HybridDictionary2 synchronized = False
-
C#のコンソールクラス
C#のConsoleクラスは、コンソールアプリケーションの標準の入力、出力、およびエラーストリームを表すために使用されます。 C#のコンソールクラスプロパティの例をいくつか見てみましょう- Console.CursorLeftプロパティ C#でコンソールのCursorLeftを変更するには、Console.CursorLeftプロパティを使用します。 例 例を見てみましょう- using System; class Demo { public static void Main (string[] args) { Cons
-
C#のバックグラウンドワーカークラス
名前が示すように、Background Worker Classを使用すると、バックグラウンドで継続的に実行され、必要に応じてメインスレッドと通信するスレッドを設定できます。 BackgroundWorkerは、Windowsフォームにスレッドを実装します。 UIがフリーズしないように、集中的なタスクを別のスレッドで実行する必要があります。タスクが完了したら、メッセージを投稿してユーザーインターフェイスを更新する必要があります。 BackgroundWorkerクラスでは次のプロパティが使用されます: 参照: Microsoft Developer Network(MSDN) S