OrderedDictionary クラス
アセンブリ: System (system.dll 内)

<SerializableAttribute> _ Public Class OrderedDictionary Implements IOrderedDictionary, IDictionary, ICollection, IEnumerable, _ ISerializable, IDeserializationCallback
[SerializableAttribute] public class OrderedDictionary : IOrderedDictionary, IDictionary, ICollection, IEnumerable, ISerializable, IDeserializationCallback
[SerializableAttribute] public ref class OrderedDictionary : IOrderedDictionary, IDictionary, ICollection, IEnumerable, ISerializable, IDeserializationCallback

各要素は、DictionaryEntry オブジェクトに格納されているキー/値ペアです。キーには null 参照 (Visual Basic では Nothing) は使用できませんが、値は null でもかまいません。
C# 言語の foreach ステートメント (Visual Basic では For Each) は、コレクション内の各要素の型を必要とします。OrderedDictionary コレクションの各要素はキー/値ペアであるため、要素の型は、キーの型や値の型にはなりません。その代わり、要素の型は DictionaryEntry になります。C# および Visual Basic の構文を次のコードに示します。
foreach (DictionaryEntry de in myListDictionary) {...}
For Each de As DictionaryEntry In myListDictionary ... Next de
foreach ステートメントは、列挙子のラッパーです。これは、コレクションからの読み取りだけを許可し、コレクションへの書き込みを防ぎます。

OrderedDictionary コレクションの作成、データの読み込み、および変更を行う方法と、OrderedDictionary の内容を表示する 2 つの方法 (Keys プロパティと Values プロパティを使用する方法、および GetEnumerator メソッドを使用して列挙子を作成する方法) のコード例を次に示します。
' The following code example enumerates the elements of a OrderedDictionary. Imports System Imports System.Collections Imports System.Collections.Specialized Public Class OrderedDictionarySample Public Shared Sub Main() ' Creates and initializes a OrderedDictionary. Dim myOrderedDictionary As New OrderedDictionary() myOrderedDictionary.Add("testKey1", "testValue1") myOrderedDictionary.Add("testKey2", "testValue2") myOrderedDictionary.Add("keyToDelete", "valueToDelete") myOrderedDictionary.Add("testKey3", "testValue3") Dim keyCollection As ICollection = myOrderedDictionary.Keys Dim valueCollection As ICollection = myOrderedDictionary.Values ' Display the contents Imports the key and value collections DisplayContents( _ keyCollection, valueCollection, myOrderedDictionary.Count) ' Modifying the OrderedDictionary If Not myOrderedDictionary.IsReadOnly Then ' Insert a new key to the beginning of the OrderedDictionary myOrderedDictionary.Insert(0, "insertedKey1", "insertedValue1") ' Modify the value of the entry with the key "testKey2" myOrderedDictionary("testKey2") = "modifiedValue" ' Remove the last entry from the OrderedDictionary: "testKey3" myOrderedDictionary.RemoveAt(myOrderedDictionary.Count - 1) ' Remove the "keyToDelete" entry, if it exists If (myOrderedDictionary.Contains("keyToDelete")) Then myOrderedDictionary.Remove("keyToDelete") End If End If Console.WriteLine( _ "{0}Displaying the entries of a modified OrderedDictionary.", _ Environment.NewLine) DisplayContents( _ keyCollection, valueCollection, myOrderedDictionary.Count) ' Clear the OrderedDictionary and add new values myOrderedDictionary.Clear() myOrderedDictionary.Add("newKey1", "newValue1") myOrderedDictionary.Add("newKey2", "newValue2") myOrderedDictionary.Add("newKey3", "newValue3") ' Display the contents of the "new" Dictionary Imports an enumerator Dim myEnumerator As IDictionaryEnumerator = _ myOrderedDictionary.GetEnumerator() Console.WriteLine( _ "{0}Displaying the entries of a 'new' OrderedDictionary.", _ Environment.NewLine) DisplayEnumerator(myEnumerator) Console.ReadLine() End Sub ' Displays the contents of the OrderedDictionary from its keys and values Public Shared Sub DisplayContents( _ ByVal keyCollection As ICollection, _ ByVal valueCollection As ICollection, ByVal dictionarySize As Integer) Dim myKeys(dictionarySize) As [String] Dim myValues(dictionarySize) As [String] keyCollection.CopyTo(myKeys, 0) valueCollection.CopyTo(myValues, 0) ' Displays the contents of the OrderedDictionary Console.WriteLine(" INDEX KEY VALUE") Dim i As Integer For i = 0 To dictionarySize - 1 Console.WriteLine(" {0,-5} {1,-25} {2}", _ i, myKeys(i), myValues(i)) Next i Console.WriteLine() End Sub ' Displays the contents of the OrderedDictionary using its enumerator Public Shared Sub DisplayEnumerator( _ ByVal myEnumerator As IDictionaryEnumerator) Console.WriteLine(" KEY VALUE") While myEnumerator.MoveNext() Console.WriteLine(" {0,-25} {1}", _ myEnumerator.Key, myEnumerator.Value) End While End Sub End Class 'This code produces the following output. ' ' INDEX KEY VALUE '0: testKey1(testValue1) '1: testKey2(testValue2) '2: keyToDelete(valueToDelete) '3: testKey3(testValue3) ' ' 'Displaying the entries of a modified OrderedDictionary. ' INDEX KEY VALUE '0: insertedKey1(insertedValue1) '1: testKey1(testValue1) '2: testKey2(modifiedValue) ' ' 'Displaying the entries of a "new" OrderedDictionary. ' KEY(VALUE) ' newKey1(newValue1) ' newKey2(newValue2) ' newKey3(newValue3)
// The following code example enumerates the elements of a OrderedDictionary. using System; using System.Collections; using System.Collections.Specialized; public class OrderedDictionarySample { public static void Main() { // Creates and initializes a OrderedDictionary. OrderedDictionary myOrderedDictionary = new OrderedDictionary(); myOrderedDictionary.Add("testKey1", "testValue1"); myOrderedDictionary.Add("testKey2", "testValue2"); myOrderedDictionary.Add("keyToDelete", "valueToDelete"); myOrderedDictionary.Add("testKey3", "testValue3"); ICollection keyCollection = myOrderedDictionary.Keys; ICollection valueCollection = myOrderedDictionary.Values; // Display the contents using the key and value collections DisplayContents(keyCollection, valueCollection, myOrderedDictionary.Count); // Modifying the OrderedDictionary if (!myOrderedDictionary.IsReadOnly) { // Insert a new key to the beginning of the OrderedDictionary myOrderedDictionary.Insert(0, "insertedKey1", "insertedValue1"); // Modify the value of the entry with the key "testKey2" myOrderedDictionary["testKey2"] = "modifiedValue"; // Remove the last entry from the OrderedDictionary: "testKey3" myOrderedDictionary.RemoveAt(myOrderedDictionary.Count - 1); // Remove the "keyToDelete" entry, if it exists if (myOrderedDictionary.Contains("keyToDelete")) { myOrderedDictionary.Remove("keyToDelete"); } } Console.WriteLine( "{0}Displaying the entries of a modified OrderedDictionary." , Environment.NewLine); DisplayContents(keyCollection, valueCollection, myOrderedDictionary.Count); // Clear the OrderedDictionary and add new values myOrderedDictionary.Clear(); myOrderedDictionary.Add("newKey1", "newValue1"); myOrderedDictionary.Add("newKey2", "newValue2"); myOrderedDictionary.Add("newKey3", "newValue3"); // Display the contents of the "new" Dictionary using an enumerator IDictionaryEnumerator myEnumerator = myOrderedDictionary.GetEnumerator(); Console.WriteLine( "{0}Displaying the entries of a \"new\" OrderedDictionary.", Environment.NewLine); DisplayEnumerator(myEnumerator); Console.ReadLine(); } // Displays the contents of the OrderedDictionary from its keys and values public static void DisplayContents( ICollection keyCollection, ICollection valueCollection, int dictionarySize) { String[] myKeys = new String[dictionarySize]; String[] myValues = new String[dictionarySize]; keyCollection.CopyTo(myKeys, 0); valueCollection.CopyTo(myValues, 0); // Displays the contents of the OrderedDictionary Console.WriteLine(" INDEX KEY VALUE"); for (int i = 0; i < dictionarySize; i++) { Console.WriteLine(" {0,-5} {1,-25} {2}", i, myKeys[i], myValues[i]); } Console.WriteLine(); } // Displays the contents of the OrderedDictionary using its enumerator public static void DisplayEnumerator(IDictionaryEnumerator myEnumerator) { Console.WriteLine(" KEY VALUE"); while (myEnumerator.MoveNext()) { Console.WriteLine(" {0,-25} {1}", myEnumerator.Key, myEnumerator.Value); } } } /* This code produces the following output. INDEX KEY VALUE 0 testKey1 testValue1 1 testKey2 testValue2 2 keyToDelete valueToDelete 3 testKey3 testValue3 Displaying the entries of a modified OrderedDictionary. INDEX KEY VALUE 0 insertedKey1 insertedValue1 1 testKey1 testValue1 2 testKey2 modifiedValue Displaying the entries of a "new" OrderedDictionary. KEY VALUE newKey1 newValue1 newKey2 newValue2 newKey3 newValue3 */

System.Collections.Specialized.OrderedDictionary
System.Web.Configuration.AdapterDictionary


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


OrderedDictionary コンストラクタ ()
アセンブリ: System (system.dll 内)


比較演算子は 2 つのキーが等しいかどうかを判断します。OrderedDictionary コレクション内のすべてのキーは一意である必要があります。既定の比較演算子は、キーの Object.Equals の実装です。

OrderedDictionary コレクションを作成してデータを読み込むコード例を次に示します。このコードは、OrderedDictionary で参照できるコード例の一部です。
' Creates and initializes a OrderedDictionary. Dim myOrderedDictionary As New OrderedDictionary() myOrderedDictionary.Add("testKey1", "testValue1") myOrderedDictionary.Add("testKey2", "testValue2") myOrderedDictionary.Add("keyToDelete", "valueToDelete") myOrderedDictionary.Add("testKey3", "testValue3") Dim keyCollection As ICollection = myOrderedDictionary.Keys Dim valueCollection As ICollection = myOrderedDictionary.Values ' Display the contents Imports the key and value collections DisplayContents( _ keyCollection, valueCollection, myOrderedDictionary.Count)
// Creates and initializes a OrderedDictionary. OrderedDictionary myOrderedDictionary = new OrderedDictionary(); myOrderedDictionary.Add("testKey1", "testValue1"); myOrderedDictionary.Add("testKey2", "testValue2"); myOrderedDictionary.Add("keyToDelete", "valueToDelete"); myOrderedDictionary.Add("testKey3", "testValue3"); ICollection keyCollection = myOrderedDictionary.Keys; ICollection valueCollection = myOrderedDictionary.Values; // Display the contents using the key and value collections DisplayContents(keyCollection, valueCollection, myOrderedDictionary.Count);

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


OrderedDictionary コンストラクタ (IEqualityComparer)
アセンブリ: System (system.dll 内)


比較演算子は 2 つのキーが等しいかどうかを判断します。OrderedDictionary コレクション内のすべてのキーは一意である必要があります。既定の比較演算子は、キーの Object.Equals の実装です。

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


OrderedDictionary コンストラクタ (Int32)
アセンブリ: System (system.dll 内)


比較演算子は 2 つのキーが等しいかどうかを判断します。OrderedDictionary コレクション内のすべてのキーは一意である必要があります。既定の比較演算子は、キーの Object.Equals の実装です。

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


OrderedDictionary コンストラクタ (Int32, IEqualityComparer)
アセンブリ: System (system.dll 内)

Dim capacity As Integer Dim comparer As IEqualityComparer Dim instance As New OrderedDictionary(capacity, comparer)

比較演算子は 2 つのキーが等しいかどうかを判断します。OrderedDictionary コレクション内のすべてのキーは一意である必要があります。既定の比較演算子は、キーの Object.Equals の実装です。

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


OrderedDictionary コンストラクタ (SerializationInfo, StreamingContext)
アセンブリ: System (system.dll 内)

Dim info As SerializationInfo Dim context As StreamingContext Dim instance As New OrderedDictionary(info, context)

比較演算子は 2 つのキーが等しいかどうかを判断します。OrderedDictionary コレクション内のすべてのキーは一意である必要があります。既定の比較演算子は、キーの Object.Equals の実装です。

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


OrderedDictionary コンストラクタ

名前 | 説明 |
---|---|
OrderedDictionary () | OrderedDictionary クラスの新しいインスタンスを初期化します。 |
OrderedDictionary (IEqualityComparer) | 比較演算子を指定して、OrderedDictionary クラスの新しいインスタンスを初期化します。 |
OrderedDictionary (Int32) | 指定した初期容量を使用して、OrderedDictionary クラスの新しいインスタンスを初期化します。 |
OrderedDictionary (Int32, IEqualityComparer) | 指定した初期容量および比較演算子を使用して、OrderedDictionary クラスの新しいインスタンスを初期化します。 |
OrderedDictionary (SerializationInfo, StreamingContext) | 指定した SerializationInfo オブジェクトと StreamingContext オブジェクトを使用してシリアル化できる、OrderedDictionary クラスの新しいインスタンスを初期化します。 |

OrderedDictionary プロパティ

名前 | 説明 | |
---|---|---|
![]() | Count | OrderedDictionary コレクションに格納されているキー/値ペアの数を取得します。 |
![]() | IsReadOnly | OrderedDictionary コレクションが読み取り専用かどうかを示す値を取得します。 |
![]() | Item | オーバーロードされます。 指定した値を取得または設定します。 |
![]() | Keys | OrderedDictionary コレクションのキーを保持している ICollection オブジェクトを取得します。 |
![]() | Values | OrderedDictionary コレクションの値を保持している ICollection オブジェクトを取得します。 |

名前 | 説明 | |
---|---|---|
![]() | System.Collections.ICollection.IsSynchronized | OrderedDictionary オブジェクトへのアクセスが同期されている (スレッド セーフである) かどうかを示す値を取得します。 |
![]() | System.Collections.ICollection.SyncRoot | OrderedDictionary オブジェクトへのアクセスを同期するために使用できるオブジェクトを取得します。 |
![]() | System.Collections.IDictionary.IsFixedSize | OrderedDictionary が固定サイズかどうかを示す値を取得します。 |

OrderedDictionary メソッド

名前 | 説明 | |
---|---|---|
![]() | Add | 指定したキーおよび値を持つエントリを、使用できる最小のインデックスを持つ OrderedDictionary コレクションに追加します。 |
![]() | AsReadOnly | 現在の OrderedDictionary コレクションの読み取り専用のコピーを返します。 |
![]() | Clear | OrderedDictionary コレクションからすべての要素を削除します。 |
![]() | Contains | OrderedDictionary コレクションに特定のキーが格納されているかどうかを判断します。 |
![]() | CopyTo | 1 次元の Array オブジェクトの指定したインデックスに OrderedDictionary の要素をコピーします。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetEnumerator | OrderedDictionary コレクションを反復処理する IDictionaryEnumerator オブジェクトを返します。 |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetObjectData | ISerializable インターフェイスを実装し、OrderedDictionary コレクションをシリアル化するために必要なデータを返します。 |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | Insert | OrderedDictionary コレクションの指定したインデックス位置に、指定したキーと値を持つ新しいエントリを挿入します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | Remove | 指定したキーを持つエントリを OrderedDictionary コレクションから削除します。 |
![]() | RemoveAt | 指定したインデックス位置にあるエントリを OrderedDictionary コレクションから削除します。 |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |
![]() | OnDeserialization | ISerializable インターフェイスを実装し、逆シリアル化が完了したときに逆シリアル化イベントによってコールバックされます。 |

名前 | 説明 | |
---|---|---|
![]() | System.Collections.IEnumerable.GetEnumerator | OrderedDictionary コレクションを反復処理する IDictionaryEnumerator オブジェクトを返します。 |
![]() | System.Runtime.Serialization.IDeserializationCallback.OnDeserialization | ISerializable インターフェイスを実装し、逆シリアル化が完了したときに逆シリアル化イベントによってコールバックされます。 |

OrderedDictionary メンバ
キーとインデックスに基づいて並べ替えられた、キー/値ペアのコレクションを表します。
OrderedDictionary データ型で公開されるメンバを以下の表に示します。



名前 | 説明 | |
---|---|---|
![]() | Count | OrderedDictionary コレクションに格納されているキー/値ペアの数を取得します。 |
![]() | IsReadOnly | OrderedDictionary コレクションが読み取り専用かどうかを示す値を取得します。 |
![]() | Item | オーバーロードされます。 指定した値を取得または設定します。 |
![]() | Keys | OrderedDictionary コレクションのキーを保持している ICollection オブジェクトを取得します。 |
![]() | Values | OrderedDictionary コレクションの値を保持している ICollection オブジェクトを取得します。 |

名前 | 説明 | |
---|---|---|
![]() | Add | 指定したキーおよび値を持つエントリを、使用できる最小のインデックスを持つ OrderedDictionary コレクションに追加します。 |
![]() | AsReadOnly | 現在の OrderedDictionary コレクションの読み取り専用のコピーを返します。 |
![]() | Clear | OrderedDictionary コレクションからすべての要素を削除します。 |
![]() | Contains | OrderedDictionary コレクションに特定のキーが格納されているかどうかを判断します。 |
![]() | CopyTo | 1 次元の Array オブジェクトの指定したインデックスに OrderedDictionary の要素をコピーします。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetEnumerator | OrderedDictionary コレクションを反復処理する IDictionaryEnumerator オブジェクトを返します。 |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetObjectData | ISerializable インターフェイスを実装し、OrderedDictionary コレクションをシリアル化するために必要なデータを返します。 |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | Insert | OrderedDictionary コレクションの指定したインデックス位置に、指定したキーと値を持つ新しいエントリを挿入します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | Remove | 指定したキーを持つエントリを OrderedDictionary コレクションから削除します。 |
![]() | RemoveAt | 指定したインデックス位置にあるエントリを OrderedDictionary コレクションから削除します。 |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |
![]() | OnDeserialization | ISerializable インターフェイスを実装し、逆シリアル化が完了したときに逆シリアル化イベントによってコールバックされます。 |

名前 | 説明 | |
---|---|---|
![]() | System.Collections.IEnumerable.GetEnumerator | OrderedDictionary コレクションを反復処理する IDictionaryEnumerator オブジェクトを返します。 |
![]() | System.Runtime.Serialization.IDeserializationCallback.OnDeserialization | ISerializable インターフェイスを実装し、逆シリアル化が完了したときに逆シリアル化イベントによってコールバックされます。 |
![]() | System.Collections.ICollection.IsSynchronized | OrderedDictionary オブジェクトへのアクセスが同期されている (スレッド セーフである) かどうかを示す値を取得します。 |
![]() | System.Collections.ICollection.SyncRoot | OrderedDictionary オブジェクトへのアクセスを同期するために使用できるオブジェクトを取得します。 |
![]() | System.Collections.IDictionary.IsFixedSize | OrderedDictionary が固定サイズかどうかを示す値を取得します。 |

- OrderedDictionaryのページへのリンク