SortedList クラス
アセンブリ: mscorlib (mscorlib.dll 内)

<SerializableAttribute> _ <ComVisibleAttribute(True)> _ Public Class SortedList Implements IDictionary, ICollection, IEnumerable, ICloneable
[SerializableAttribute] [ComVisibleAttribute(true)] public class SortedList : IDictionary, ICollection, IEnumerable, ICloneable
[SerializableAttribute] [ComVisibleAttribute(true)] public ref class SortedList : IDictionary, ICollection, IEnumerable, ICloneable

このコレクションのジェネリック バージョンについては、「System.Collections.Generic.SortedList」を参照してください。
SortedList 要素にアクセスするには、IDictionary 実装内の要素のようにキーを使用するか、IList 実装内の要素のようにインデックスを使用します。
SortedList は、リストの要素を格納するために、内部に 2 つの配列を保持しています。一方の配列にはキーを格納し、他方の配列にはキーに関連付けられている値を格納します。各要素はキー/値ペアであり、DictionaryEntry オブジェクトとしてアクセスできます。キーには null 参照 (Visual Basic では Nothing) は使用できませんが、値は null でもかまいません。
SortedList の容量は、SortedList が保持できる要素数になります。SortedList の既定の初期量は 0 です。SortedList に要素を追加すると、必要に応じて、再割り当てによって容量が自動的に増加します。容量を減らすには、TrimToSize を呼び出すか、Capacity プロパティを明示的に設定します。
SortedList の要素は、SortedList が作成されるときに指定された IComparer の特定の実装か、キー自体が提供する IComparable 実装のいずれかに従って並べ替えられます。いずれの場合でも、SortedList では、キーが重複することはあり得ません。
並べ替え順に基づいたインデックス順。要素を追加すると、その要素は正しい並べ替え順に従って SortedList に挿入され、それに応じてインデックスも調整されます。要素が削除されると、それに応じてインデックスも調整されます。したがって、特定のキー/値ペアのインデックスは、要素が SortedList で追加または削除されるときに変更されることがあります。
SortedList に対する操作は、並べ替えが必要になるため、Hashtable に対する操作よりも遅くなる傾向があります。ただし、SortedList では、関連付けられているキーまたはインデックスのどちらを使用しても値にアクセスできるため、柔軟性という面ではより優れています。
このコレクション内の要素は、整数インデックスを使用してアクセスできます。このコレクションのインデックスは 0 から始まります。
C# 言語の foreach ステートメント (Visual Basic では for each) は、コレクション内の各要素の型を必要とします。SortedList の各要素はキー/値ペアであるため、要素の型は、キーの型や値の型にはなりません。その代わり、要素の型は DictionaryEntry になります。例 :
foreach (DictionaryEntry de in mySortedList) {...}
For Each de As DictionaryEntry In mySortedList ... Next myDE
foreach ステートメントは、列挙子のラッパーです。これは、コレクションからの読み取りだけを許可し、コレクションへの書き込みを防ぎます。

SortedList を作成および初期化する方法と、そのキーと値を出力する方法の例を次に示します。
Imports System Imports System.Collections Imports Microsoft.VisualBasic Public Class SamplesSortedList Public Shared Sub Main() ' Creates and initializes a new SortedList. Dim mySL As New SortedList() mySL.Add("First", "Hello") mySL.Add("Second", "World") mySL.Add("Third", "!") ' Displays the properties and values of the SortedList. Console.WriteLine("mySL") Console.WriteLine(" Count: {0}", mySL.Count) Console.WriteLine(" Capacity: {0}", mySL.Capacity) Console.WriteLine(" Keys and Values:") PrintKeysAndValues(mySL) End Sub Public Shared Sub PrintKeysAndValues(myList As SortedList) Console.WriteLine(ControlChars.Tab & "-KEY-" & ControlChars.Tab & _ "-VALUE-") Dim i As Integer For i = 0 To myList.Count - 1 Console.WriteLine(ControlChars.Tab & "{0}:" & ControlChars.Tab & _ "{1}", myList.GetKey(i), myList.GetByIndex(i)) Next i Console.WriteLine() End Sub End Class ' This code produces the following output. ' ' mySL ' Count: 3 ' Capacity: 16 ' Keys and Values: ' -KEY- -VALUE- ' First: Hello ' Second: World ' Third: !
using System; using System.Collections; public class SamplesSortedList { public static void Main() { // Creates and initializes a new SortedList. SortedList mySL = new SortedList(); mySL.Add("First", "Hello"); mySL.Add("Second", "World"); mySL.Add("Third", "!"); // Displays the properties and values of the SortedList. Console.WriteLine( "mySL" ); Console.WriteLine( " Count: {0}", mySL.Count ); Console.WriteLine( " Capacity: {0}", mySL.Capacity ); Console.WriteLine( " Keys and Values:" ); PrintKeysAndValues( mySL ); } public static void PrintKeysAndValues( SortedList myList ) { Console.WriteLine( "\t-KEY-\t-VALUE-" ); for ( int i = 0; i < myList.Count; i++ ) { Console.WriteLine( "\t{0}:\t{1}", myList.GetKey(i), myList.GetByIndex(i) ); } Console.WriteLine(); } } /* This code produces the following output. mySL Count: 3 Capacity: 16 Keys and Values: -KEY- -VALUE- First: Hello Second: World Third: ! */
#using <system.dll> using namespace System; using namespace System::Collections; public ref class SamplesSortedList { public: static void PrintKeysAndValues( SortedList^ myList ) { Console::WriteLine( "\t-KEY-\t-VALUE-" ); for ( int i = 0; i < myList->Count; i++ ) { Console::WriteLine( "\t{0}:\t{1}", myList->GetKey( i ), myList->GetByIndex( i ) ); } Console::WriteLine(); } }; int main() { // Creates and initializes a new SortedList. SortedList^ mySL = gcnew SortedList; mySL->Add( "First", "Hello" ); mySL->Add( "Second", "World" ); mySL->Add( "Third", "!" ); // Displays the properties and values of the SortedList. Console::WriteLine( "mySL" ); Console::WriteLine( " Count: {0}", mySL->Count ); Console::WriteLine( " Capacity: {0}", mySL->Capacity ); Console::WriteLine( " Keys and Values:" ); SamplesSortedList::PrintKeysAndValues( mySL ); } /* This code produces the following output. mySL Count: 3 Capacity: 16 Keys and Values: -KEY- -VALUE- First: Hello Second: World Third: ! */
import System.*; import System.Collections.*; public class SamplesSortedList { public static void main(String[] args) { // Creates and initializes a new SortedList. SortedList mySL = new SortedList(); mySL.Add("First", "Hello"); mySL.Add("Second", "World"); mySL.Add("Third", "!"); // Displays the properties and values of the SortedList. Console.WriteLine("mySL"); Console.WriteLine(" Count: {0}", System.Convert.ToString(mySL.get_Count())); Console.WriteLine(" Capacity: {0}", System.Convert.ToString(mySL.get_Capacity())); Console.WriteLine(" Keys and Values:"); PrintKeysAndValues(mySL); } //main public static void PrintKeysAndValues(SortedList myList) { Console.WriteLine("\t-KEY-\t-VALUE-"); for (int i = 0; i < myList.get_Count(); i++) { Console.WriteLine("\t{0}:\t{1}", myList.GetKey(i), myList.GetByIndex(i)); } Console.WriteLine(); } //PrintKeysAndValues } //SamplesSortedList /* This code produces the following output. mySL Count: 3 Capacity: 16 Keys and Values: -KEY- -VALUE- First: Hello Second: World Third: ! */

System.Collections.SortedList

この型の public static (Visual Basic では Shared) メンバは、スレッド セーフです。すべてのインスタンス メンバがスレッド セーフになるかどうかは保証されていません。
コレクションが変更されない限り、SortedList では、複数の読み込み操作が同時に発生しても問題ありません。SortedList を確実にスレッド セーフにするためには、すべての操作を Synchronized メソッドから返されるラッパー経由で実行する必要があります。
コレクションの列挙処理は、本質的にはスレッド セーフな処理ではありません。コレクションが同期されている場合でも、他のスレッドがそのコレクションを変更する可能性はあり、そのような状況が発生すると列挙子は例外をスローします。列挙処理を確実にスレッド セーフに行うには、列挙中にコレクションをロックするか、他のスレッドによって行われた変更によってスローされる例外をキャッチします。

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


SortedList コンストラクタ ()
アセンブリ: mscorlib (mscorlib.dll 内)


各キーは、SortedList 内の他のキーとの比較を行うことができるように、IComparable インターフェイスを実装する必要があります。要素は、SortedList に追加された各キーの IComparable 実装に基づいて並べ替えられます。
SortedList の容量は、SortedList が保持できる要素数になります。SortedList に要素を追加すると、必要に応じて、内部の配列の再割り当てによって容量が自動的に増加します。
コレクションのサイズを推定できる場合は、初期量を指定すると、SortedList に要素を追加するときに、サイズ変更操作を何度も実行する必要がなくなります。

異なる SortedList コンストラクタを使用してコレクションを作成し、各コレクションの動作の違いを示すコード例を次に示します。
Imports System Imports System.Collections Imports System.Globalization Public Class SamplesSortedList Public Shared Sub Main() ' Create a SortedList using the default comparer. Dim mySL1 As New SortedList() Console.WriteLine("mySL1 (default):") mySL1.Add("FIRST", "Hello") mySL1.Add("SECOND", "World") mySL1.Add("THIRD", "!") Try mySL1.Add("first", "Ola!") Catch e As ArgumentException Console.WriteLine(e) End Try PrintKeysAndValues(mySL1) ' Create a SortedList using the specified case-insensitive comparer. Dim mySL2 As New SortedList(New CaseInsensitiveComparer()) Console.WriteLine("mySL2 (case-insensitive comparer):") mySL2.Add("FIRST", "Hello") mySL2.Add("SECOND", "World") mySL2.Add("THIRD", "!") Try mySL2.Add("first", "Ola!") Catch e As ArgumentException Console.WriteLine(e) End Try PrintKeysAndValues(mySL2) ' Create a SortedList using the specified CaseInsensitiveComparer , ' which is based on the Turkish culture (tr-TR), where "I" is not ' the uppercase version of "i". Dim myCul As New CultureInfo("tr-TR") Dim mySL3 As New SortedList(New CaseInsensitiveComparer(myCul)) Console.WriteLine("mySL3 (case-insensitive comparer, Turkish culture):") mySL3.Add("FIRST", "Hello") mySL3.Add("SECOND", "World") mySL3.Add("THIRD", "!") Try mySL3.Add("first", "Ola!") Catch e As ArgumentException Console.WriteLine(e) End Try PrintKeysAndValues(mySL3) ' Create a SortedList using the ' StringComparer.InvariantCultureIgnoreCase value. Dim mySL4 As New SortedList( _ StringComparer.InvariantCultureIgnoreCase) Console.WriteLine("mySL4 (InvariantCultureIgnoreCase):") mySL4.Add("FIRST", "Hello") mySL4.Add("SECOND", "World") mySL4.Add("THIRD", "!") Try mySL4.Add("first", "Ola!") Catch e As ArgumentException Console.WriteLine(e) End Try PrintKeysAndValues(mySL4) End Sub 'Main Public Shared Sub PrintKeysAndValues(ByVal myList As SortedList) Console.WriteLine(" -KEY- -VALUE-") Dim i As Integer For i = 0 To myList.Count - 1 Console.WriteLine(" {0,-6}: {1}", _ myList.GetKey(i), myList.GetByIndex(i)) Next i Console.WriteLine() End Sub 'PrintKeysAndValues End Class 'SamplesSortedList 'This code produces the following output. Results vary depending on the system's culture settings. ' 'mySL1 (default): ' -KEY- -VALUE- ' first : Ola! ' FIRST : Hello ' SECOND: World ' THIRD : ! ' 'mySL2 (case-insensitive comparer): 'System.ArgumentException: Item has already been added. Key in dictionary: 'FIRST' Key being added: 'first'' at System.Collections.SortedList.Add(Object key, Object value) ' at SamplesSortedList.Main() ' -KEY- -VALUE- ' FIRST : Hello ' SECOND: World ' THIRD : ! ' 'mySL3 (case-insensitive comparer, Turkish culture): ' -KEY- -VALUE- ' FIRST : Hello ' first : Ola! ' SECOND: World ' THIRD : ! ' 'mySL4 (InvariantCultureIgnoreCase): 'System.ArgumentException: Item has already been added. Key in dictionary: 'FIRST' Key being added: 'first'' at System.Collections.SortedList.Add(Object key, Object value) ' at SamplesSortedList.Main() ' -KEY- -VALUE- ' FIRST : Hello ' SECOND: World ' THIRD : !
using System; using System.Collections; using System.Globalization; public class SamplesSortedList { public static void Main() { // Create a SortedList using the default comparer. SortedList mySL1 = new SortedList(); Console.WriteLine("mySL1 (default):"); mySL1.Add("FIRST", "Hello"); mySL1.Add("SECOND", "World"); mySL1.Add("THIRD", "!"); try { mySL1.Add("first", "Ola!"); } catch (ArgumentException e) { Console.WriteLine(e); } PrintKeysAndValues(mySL1); // Create a SortedList using the specified case-insensitive comparer. SortedList mySL2 = new SortedList(new CaseInsensitiveComparer()); Console.WriteLine("mySL2 (case-insensitive comparer):"); mySL2.Add("FIRST", "Hello"); mySL2.Add("SECOND", "World"); mySL2.Add("THIRD", "!"); try { mySL2.Add("first", "Ola!"); } catch (ArgumentException e) { Console.WriteLine(e); } PrintKeysAndValues(mySL2); // Create a SortedList using the specified CaseInsensitiveComparer , // which is based on the Turkish culture (tr-TR), where "I" is not // the uppercase version of "i". CultureInfo myCul = new CultureInfo("tr-TR"); SortedList mySL3 = new SortedList(new CaseInsensitiveComparer(myCul)); Console.WriteLine( "mySL3 (case-insensitive comparer, Turkish culture):"); mySL3.Add("FIRST", "Hello"); mySL3.Add("SECOND", "World"); mySL3.Add("THIRD", "!"); try { mySL3.Add("first", "Ola!"); } catch (ArgumentException e) { Console.WriteLine(e); } PrintKeysAndValues(mySL3); // Create a SortedList using the // StringComparer.InvariantCultureIgnoreCase value. SortedList mySL4 = new SortedList( StringComparer.InvariantCultureIgnoreCase); Console.WriteLine("mySL4 (InvariantCultureIgnoreCase):"); mySL4.Add("FIRST", "Hello"); mySL4.Add("SECOND", "World"); mySL4.Add("THIRD", "!"); try { mySL4.Add("first", "Ola!"); } catch (ArgumentException e) { Console.WriteLine(e); } PrintKeysAndValues(mySL4); } public static void PrintKeysAndValues(SortedList myList) { Console.WriteLine(" -KEY- -VALUE-"); for (int i = 0; i < myList.Count; i++) { Console.WriteLine(" {0,-6}: {1}", myList.GetKey(i), myList.GetByIndex(i)); } Console.WriteLine(); } } /* This code produces the following output. Results vary depending on the system's culture settings. mySL1 (default): -KEY- -VALUE- first : Ola! FIRST : Hello SECOND: World THIRD : ! mySL2 (case-insensitive comparer): System.ArgumentException: Item has already been added. Key in dictionary: 'FIRST' Key being added: 'first' at System.Collections.SortedList.Add(Object key, Object value) at SamplesSortedList.Main() -KEY- -VALUE- FIRST : Hello SECOND: World THIRD : ! mySL3 (case-insensitive comparer, Turkish culture): -KEY- -VALUE- FIRST : Hello first : Ola! SECOND: World THIRD : ! mySL4 (InvariantCultureIgnoreCase): System.ArgumentException: Item has already been added. Key in dictionary: 'FIRST' Key being added: 'first' at System.Collections.SortedList.Add(Object key, Object value) at SamplesSortedList.Main() -KEY- -VALUE- FIRST : Hello SECOND: World THIRD : ! */

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


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


SortedList 内のすべてのキーは既定の比較演算子に従って一意である必要があります。
このコンストラクタは、SortedList の初期量として既定値を使用します。初期量を設定するには、SortedList(Int32) コンストラクタを使用します。コレクションの最終的なサイズを推定できる場合、初期量を指定すると、SortedList に要素を追加するときにサイズ変更操作を何度も実行する必要がなくなります。
このコンストラクタは、TKey の既定の比較演算子を使用します。比較演算子を指定するには、SortedList(ジェネリック IComparer) コンストラクタを使用します。既定の比較演算子 Comparer.Default は、キーの型 TKey が System.IComparable を実装し、利用可能な場合はその実装を使用するかどうかをチェックします。それ以外の場合は、Comparer.Default によって、キーの型 TKey が System.IComparable を実装するかどうかをチェックします。キーの型 TKey がいずれのインターフェイスも実装しない場合は、comparer パラメータを受け取るコンストラクタ オーバーロードの System.Collections.Generic.IComparer 実装を指定できます。

文字列キーを含む文字列の空の SortedList を作成し、Add メソッドを使用していくつかの要素を追加するコード例を次に示します。この例では、重複するキーを追加しようとすると、Add メソッドが ArgumentException をスローすることを示します。
このコード例は、SortedList クラスのトピックで取り上げているコード例の一部分です。
' Create a new sorted list of strings, with string ' keys. Dim openWith As New SortedList(Of String, String) ' Add some elements to the list. There are no ' duplicate keys, but some of the values are duplicates. openWith.Add("txt", "notepad.exe") openWith.Add("bmp", "paint.exe") openWith.Add("dib", "paint.exe") openWith.Add("rtf", "wordpad.exe") ' The Add method throws an exception if the new key is ' already in the list. Try openWith.Add("txt", "winword.exe") Catch Console.WriteLine("An element with Key = ""txt"" already exists.") End Try
// Create a new sorted list of strings, with string // keys. SortedList<string, string> openWith = new SortedList<string, string>(); // Add some elements to the list. There are no // duplicate keys, but some of the values are duplicates. openWith.Add("txt", "notepad.exe"); openWith.Add("bmp", "paint.exe"); openWith.Add("dib", "paint.exe"); openWith.Add("rtf", "wordpad.exe"); // The Add method throws an exception if the new key is // already in the list. try { openWith.Add("txt", "winword.exe"); } catch (ArgumentException) { Console.WriteLine("An element with Key = \"txt\" already exists."); }

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


SortedList ジェネリック クラス
SortedList メンバ
System.Collections.Generic 名前空間
Comparer.Default プロパティ
IComparable ジェネリック インターフェイス
IComparable インターフェイス
SortedList コンストラクタ (IDictionary)
アセンブリ: mscorlib (mscorlib.dll 内)



各キーは、SortedList 内の他のキーとの比較を行うことができるように、IComparable インターフェイスを実装する必要があります。要素は、SortedList に追加された各キーの IComparable 実装に基づいて並べ替えられます。
Hashtable は、このコンストラクタに渡すことができる IDictionary 実装の一例です。新しい SortedList には、Hashtable で並べ替えられたキーと値のコピーが格納されます。
SortedList の容量は、SortedList が保持できる要素数になります。SortedList に要素を追加すると、必要に応じて、内部の配列の再割り当てによって容量が自動的に増加します。
コレクションのサイズを推定できる場合は、初期量を指定すると、SortedList に要素を追加するときに、サイズ変更操作を何度も実行する必要がなくなります。

異なる SortedList コンストラクタを使用してコレクションを作成し、各コレクションの動作の違いを示すコード例を次に示します。
Imports System Imports System.Collections Imports System.Globalization Public Class SamplesSortedList Public Shared Sub Main() ' Create the dictionary. Dim myHT As New Hashtable() myHT.Add("FIRST", "Hello") myHT.Add("SECOND", "World") myHT.Add("THIRD", "!") ' Create a SortedList using the default comparer. Dim mySL1 As New SortedList(myHT) Console.WriteLine("mySL1 (default):") Try mySL1.Add("first", "Ola!") Catch e As ArgumentException Console.WriteLine(e) End Try PrintKeysAndValues(mySL1) ' Create a SortedList using the specified case-insensitive comparer. Dim mySL2 As New SortedList(myHT, New CaseInsensitiveComparer()) Console.WriteLine("mySL2 (case-insensitive comparer):") Try mySL2.Add("first", "Ola!") Catch e As ArgumentException Console.WriteLine(e) End Try PrintKeysAndValues(mySL2) ' Create a SortedList using the specified CaseInsensitiveComparer , ' which is based on the Turkish culture (tr-TR), where "I" is not ' the uppercase version of "i". Dim myCul As New CultureInfo("tr-TR") Dim mySL3 As New SortedList(myHT, New CaseInsensitiveComparer(myCul)) Console.WriteLine("mySL3 (case-insensitive comparer, Turkish culture):") Try mySL3.Add("first", "Ola!") Catch e As ArgumentException Console.WriteLine(e) End Try PrintKeysAndValues(mySL3) ' Create a SortedList using the ' StringComparer.InvariantCultureIgnoreCase value. Dim mySL4 As New SortedList(myHT, StringComparer.InvariantCultureIgnoreCase) Console.WriteLine("mySL4 (InvariantCultureIgnoreCase):") Try mySL4.Add("first", "Ola!") Catch e As ArgumentException Console.WriteLine(e) End Try PrintKeysAndValues(mySL4) End Sub 'Main Public Shared Sub PrintKeysAndValues(ByVal myList As SortedList) Console.WriteLine(" -KEY- -VALUE-") Dim i As Integer For i = 0 To myList.Count - 1 Console.WriteLine(" {0,-6}: {1}", _ myList.GetKey(i), myList.GetByIndex(i)) Next i Console.WriteLine() End Sub 'PrintKeysAndValues End Class 'SamplesSortedList 'This code produces the following output. Results vary depending on the system's culture settings. ' 'mySL1 (default): ' -KEY- -VALUE- ' first : Ola! ' FIRST : Hello ' SECOND: World ' THIRD : ! ' 'mySL2 (case-insensitive comparer): 'System.ArgumentException: Item has already been added. Key in dictionary: 'FIRST' Key being added: 'first'' at System.Collections.SortedList.Add(Object key, Object value) ' at SamplesSortedList.Main() ' -KEY- -VALUE- ' FIRST : Hello ' SECOND: World ' THIRD : ! ' 'mySL3 (case-insensitive comparer, Turkish culture): ' -KEY- -VALUE- ' FIRST : Hello ' first : Ola! ' SECOND: World ' THIRD : ! ' 'mySL4 (InvariantCultureIgnoreCase): 'System.ArgumentException: Item has already been added. Key in dictionary: 'FIRST' Key being added: 'first'' at System.Collections.SortedList.Add(Object key, Object value) ' at SamplesSortedList.Main() ' -KEY- -VALUE- ' FIRST : Hello ' SECOND: World ' THIRD : !
using System; using System.Collections; using System.Globalization; public class SamplesSortedList { public static void Main() { // Create the dictionary. Hashtable myHT = new Hashtable(); myHT.Add("FIRST", "Hello"); myHT.Add("SECOND", "World"); myHT.Add("THIRD", "!"); // Create a SortedList using the default comparer. SortedList mySL1 = new SortedList(myHT); Console.WriteLine("mySL1 (default):"); try { mySL1.Add("first", "Ola!"); } catch (ArgumentException e) { Console.WriteLine(e); } PrintKeysAndValues(mySL1); // Create a SortedList using the specified case-insensitive comparer. SortedList mySL2 = new SortedList(myHT, new CaseInsensitiveComparer()); Console.WriteLine("mySL2 (case-insensitive comparer):"); try { mySL2.Add("first", "Ola!"); } catch (ArgumentException e) { Console.WriteLine(e); } PrintKeysAndValues(mySL2); // Create a SortedList using the specified CaseInsensitiveComparer , // which is based on the Turkish culture (tr-TR), where "I" is not // the uppercase version of "i". CultureInfo myCul = new CultureInfo("tr-TR"); SortedList mySL3 = new SortedList(myHT, new CaseInsensitiveComparer(myCul)); Console.WriteLine("mySL3 (case-insensitive comparer, Turkish culture):"); try { mySL3.Add("first", "Ola!"); } catch (ArgumentException e) { Console.WriteLine(e); } PrintKeysAndValues(mySL3); // Create a SortedList using the // StringComparer.InvariantCultureIgnoreCase value. SortedList mySL4 = new SortedList( myHT, StringComparer.InvariantCultureIgnoreCase); Console.WriteLine("mySL4 (InvariantCultureIgnoreCase):"); try { mySL4.Add("first", "Ola!"); } catch (ArgumentException e) { Console.WriteLine(e); } PrintKeysAndValues(mySL4); } public static void PrintKeysAndValues(SortedList myList) { Console.WriteLine(" -KEY- -VALUE-"); for (int i = 0; i < myList.Count; i++) { Console.WriteLine(" {0,-6}: {1}", myList.GetKey(i), myList.GetByIndex(i)); } Console.WriteLine(); } } /* This code produces the following output. Results vary depending on the system's culture settings. mySL1 (default): -KEY- -VALUE- first : Ola! FIRST : Hello SECOND: World THIRD : ! mySL2 (case-insensitive comparer): System.ArgumentException: Item has already been added. Key in dictionary: 'FIRST' Key being added: 'first' at System.Collections.SortedList.Add(Object key, Object value) at SamplesSortedList.Main() -KEY- -VALUE- FIRST : Hello SECOND: World THIRD : ! mySL3 (case-insensitive comparer, Turkish culture): -KEY- -VALUE- FIRST : Hello first : Ola! SECOND: World THIRD : ! mySL4 (InvariantCultureIgnoreCase): System.ArgumentException: Item has already been added. Key in dictionary: 'FIRST' Key being added: 'first' at System.Collections.SortedList.Add(Object key, Object value) at SamplesSortedList.Main() -KEY- -VALUE- FIRST : Hello SECOND: World THIRD : ! */

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


SortedList コンストラクタ (Int32, ジェネリック IComparer)
アセンブリ: System (system.dll 内)

Dim capacity As Integer Dim comparer As IComparer(Of TKey) Dim instance As New SortedList(Of TKey, TValue)(capacity, comparer)


SortedList 内のすべてのキーは指定した比較演算子に従って一意である必要があります。
SortedList の容量は、サイズ変更前に SortedList が保持できる要素数になります。SortedList に要素を追加すると、必要に応じて、内部の配列の再割り当てによって容量が自動的に増加します。
コレクションのサイズを推定できる場合は、初期量を指定すると、SortedList に要素を追加するときに、サイズ変更操作を何度も実行する必要がなくなります。
容量を減らすには、TrimExcess を呼び出すか、Capacity プロパティを明示的に設定します。容量を減らすと、メモリの再割り当てが行われ、SortedList 内のすべての要素がコピーされます。

初期量 5 で、現在のカルチャの大文字小文字を区別しない比較演算子を使って、並べ替えられたリストを作成するコード例を次に示します。この例では、小文字のキーを含む要素と大文字のキーを含む要素を合わせて 4 つの要素を追加します。次に、既存のキーとの違いが大文字と小文字の違いだけであるキーを含む要素の追加を試行し、結果の例外をキャッチし、エラー メッセージを表示します。最後に、大文字小文字を区別しない並べ替え順で要素を表示します。
Imports System Imports System.Collections.Generic Public Class Example Public Shared Sub Main() ' Create a new sorted list of strings, with string keys, an ' initial capacity of 5, and a case-insensitive comparer. Dim openWith As New SortedList(Of String, String)(5, _ StringComparer.CurrentCultureIgnoreCase) ' Add 4 elements to the list. openWith.Add("txt", "notepad.exe") openWith.Add("bmp", "paint.exe") openWith.Add("DIB", "paint.exe") openWith.Add("rtf", "wordpad.exe") ' Try to add a fifth element with a key that is the same ' except for case; this would be allowed with the default ' comparer. Try openWith.Add("BMP", "paint.exe") Catch ex As ArgumentException Console.WriteLine(vbLf & "BMP is already in the sorted list.") End Try ' List the contents of the sorted list. Console.WriteLine() For Each kvp As KeyValuePair(Of String, String) In openWith Console.WriteLine("Key = {0}, Value = {1}", _ kvp.Key, kvp.Value) Next kvp End Sub End Class ' This code example produces the following output: ' 'BMP is already in the sorted list. ' 'Key = bmp, Value = paint.exe 'Key = DIB, Value = paint.exe 'Key = rtf, Value = wordpad.exe 'Key = txt, Value = notepad.exe
using System; using System.Collections.Generic; public class Example { public static void Main() { // Create a new sorted list of strings, with string keys, an // initial capacity of 5, and a case-insensitive comparer. SortedList<string, string> openWith = new SortedList<string, string>(5, StringComparer.CurrentCultureIgnoreCase); // Add 4 elements to the list. openWith.Add("txt", "notepad.exe"); openWith.Add("bmp", "paint.exe"); openWith.Add("DIB", "paint.exe"); openWith.Add("rtf", "wordpad.exe"); // Try to add a fifth element with a key that is the same // except for case; this would be allowed with the default // comparer. try { openWith.Add("BMP", "paint.exe"); } catch (ArgumentException) { Console.WriteLine("\nBMP is already in the sorted list."); } // List the contents of the sorted list. Console.WriteLine(); foreach( KeyValuePair<string, string> kvp in openWith ) { Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value); } } } /* This code example produces the following output: BMP is already in the sorted list. Key = bmp, Value = paint.exe Key = DIB, Value = paint.exe Key = rtf, Value = wordpad.exe Key = txt, Value = notepad.exe */

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


SortedList ジェネリック クラス
SortedList メンバ
System.Collections.Generic 名前空間
Capacity
IComparer ジェネリック インターフェイス
Comparer.Default プロパティ
IComparable ジェネリック インターフェイス
IComparable インターフェイス
SortedList コンストラクタ

名前 | 説明 |
---|---|
SortedList () | 空で、既定の初期量を備え、SortedList に追加された各キーによって実装されている IComparable インターフェイスに従って並べ替えられた、SortedList クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
SortedList (IComparer) | 空で、既定の初期量を備え、指定した IComparer インターフェイスに従って並べ替えられた、SortedList クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
SortedList (IDictionary) | 指定したディクショナリからコピーした要素を格納し、コピーした要素の数と同じ初期量を備え、各キーによって実装されている IComparable インターフェイスに従って並べ替えられた、SortedList クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
SortedList (Int32) | 空で、既定の初期量を備え、SortedList に追加された各キーによって実装されている IComparable インターフェイスに従って並べ替えられた、SortedList クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
SortedList (IComparer, Int32) | 空で、指定した初期量を備え、指定した IComparer インターフェイスに従って並べ替えられた、SortedList クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
SortedList (IDictionary, IComparer) | 指定したディクショナリからコピーした要素を格納し、コピーした要素の数と同じ初期量を備え、指定した IComparer インターフェイスに従って並べ替えられた、SortedList クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |

SortedList コンストラクタ (Int32)
アセンブリ: mscorlib (mscorlib.dll 内)



各キーは、SortedList 内の他のキーとの比較を行うことができるように、IComparable インターフェイスを実装する必要があります。要素は、SortedList に追加された各キーの IComparable 実装に基づいて並べ替えられます。
SortedList の容量は、SortedList が保持できる要素数になります。SortedList に要素を追加すると、必要に応じて、内部の配列の再割り当てによって容量が自動的に増加します。
コレクションのサイズを推定できる場合は、初期量を指定すると、SortedList に要素を追加するときに、サイズ変更操作を何度も実行する必要がなくなります。

異なる SortedList コンストラクタを使用してコレクションを作成し、各コレクションの動作の違いを示すコード例を次に示します。
Imports System Imports System.Collections Imports System.Globalization Public Class SamplesSortedList Public Shared Sub Main() ' Create a SortedList using the default comparer. Dim mySL1 As New SortedList( 3 ) Console.WriteLine("mySL1 (default):") mySL1.Add("FIRST", "Hello") mySL1.Add("SECOND", "World") mySL1.Add("THIRD", "!") Try mySL1.Add("first", "Ola!") Catch e As ArgumentException Console.WriteLine(e) End Try PrintKeysAndValues(mySL1) ' Create a SortedList using the specified case-insensitive comparer. Dim mySL2 As New SortedList(New CaseInsensitiveComparer(), 3) Console.WriteLine("mySL2 (case-insensitive comparer):") mySL2.Add("FIRST", "Hello") mySL2.Add("SECOND", "World") mySL2.Add("THIRD", "!") Try mySL2.Add("first", "Ola!") Catch e As ArgumentException Console.WriteLine(e) End Try PrintKeysAndValues(mySL2) ' Create a SortedList using the specified CaseInsensitiveComparer , ' which is based on the Turkish culture (tr-TR), where "I" is not ' the uppercase version of "i". Dim myCul As New CultureInfo("tr-TR") Dim mySL3 As New SortedList(New CaseInsensitiveComparer(myCul), 3) Console.WriteLine("mySL3 (case-insensitive comparer, Turkish culture):") mySL3.Add("FIRST", "Hello") mySL3.Add("SECOND", "World") mySL3.Add("THIRD", "!") Try mySL3.Add("first", "Ola!") Catch e As ArgumentException Console.WriteLine(e) End Try PrintKeysAndValues(mySL3) ' Create a SortedList using the ' StringComparer.InvariantCultureIgnoreCase value. Dim mySL4 As New SortedList( _ StringComparer.InvariantCultureIgnoreCase, 3) Console.WriteLine("mySL4 (InvariantCultureIgnoreCase):") mySL4.Add("FIRST", "Hello") mySL4.Add("SECOND", "World") mySL4.Add("THIRD", "!") Try mySL4.Add("first", "Ola!") Catch e As ArgumentException Console.WriteLine(e) End Try PrintKeysAndValues(mySL4) End Sub 'Main Public Shared Sub PrintKeysAndValues(ByVal myList As SortedList) Console.WriteLine(" -KEY- -VALUE-") Dim i As Integer For i = 0 To myList.Count - 1 Console.WriteLine(" {0,-6}: {1}", _ myList.GetKey(i), myList.GetByIndex(i)) Next i Console.WriteLine() End Sub 'PrintKeysAndValues End Class 'SamplesSortedList 'This code produces the following output. Results vary depending on the system's culture settings. ' 'mySL1 (default): ' -KEY- -VALUE- ' first : Ola! ' FIRST : Hello ' SECOND: World ' THIRD : ! ' 'mySL2 (case-insensitive comparer): 'System.ArgumentException: Item has already been added. Key in dictionary: 'FIRST' Key being added: 'first'' at System.Collections.SortedList.Add(Object key, Object value) ' at SamplesSortedList.Main() ' -KEY- -VALUE- ' FIRST : Hello ' SECOND: World ' THIRD : ! ' 'mySL3 (case-insensitive comparer, Turkish culture): ' -KEY- -VALUE- ' FIRST : Hello ' first : Ola! ' SECOND: World ' THIRD : ! ' 'mySL4 (InvariantCultureIgnoreCase): 'System.ArgumentException: Item has already been added. Key in dictionary: 'FIRST' Key being added: 'first'' at System.Collections.SortedList.Add(Object key, Object value) ' at SamplesSortedList.Main() ' -KEY- -VALUE- ' FIRST : Hello ' SECOND: World ' THIRD : !
using System; using System.Collections; using System.Globalization; public class SamplesSortedList { public static void Main() { // Create a SortedList using the default comparer. SortedList mySL1 = new SortedList( 3 ); Console.WriteLine("mySL1 (default):"); mySL1.Add("FIRST", "Hello"); mySL1.Add("SECOND", "World"); mySL1.Add("THIRD", "!"); try { mySL1.Add("first", "Ola!"); } catch (ArgumentException e) { Console.WriteLine(e); } PrintKeysAndValues(mySL1); // Create a SortedList using the specified case-insensitive comparer. SortedList mySL2 = new SortedList(new CaseInsensitiveComparer(), 3); Console.WriteLine("mySL2 (case-insensitive comparer):"); mySL2.Add("FIRST", "Hello"); mySL2.Add("SECOND", "World"); mySL2.Add("THIRD", "!"); try { mySL2.Add("first", "Ola!"); } catch (ArgumentException e) { Console.WriteLine(e); } PrintKeysAndValues(mySL2); // Create a SortedList using the specified CaseInsensitiveComparer , // which is based on the Turkish culture (tr-TR), where "I" is not // the uppercase version of "i". CultureInfo myCul = new CultureInfo("tr-TR"); SortedList mySL3 = new SortedList(new CaseInsensitiveComparer(myCul), 3); Console.WriteLine( "mySL3 (case-insensitive comparer, Turkish culture):"); mySL3.Add("FIRST", "Hello"); mySL3.Add("SECOND", "World"); mySL3.Add("THIRD", "!"); try { mySL3.Add("first", "Ola!"); } catch (ArgumentException e) { Console.WriteLine(e); } PrintKeysAndValues(mySL3); // Create a SortedList using the // StringComparer.InvariantCultureIgnoreCase value. SortedList mySL4 = new SortedList( StringComparer.InvariantCultureIgnoreCase, 3); Console.WriteLine("mySL4 (InvariantCultureIgnoreCase):"); mySL4.Add("FIRST", "Hello"); mySL4.Add("SECOND", "World"); mySL4.Add("THIRD", "!"); try { mySL4.Add("first", "Ola!"); } catch (ArgumentException e) { Console.WriteLine(e); } PrintKeysAndValues(mySL4); } public static void PrintKeysAndValues(SortedList myList) { Console.WriteLine(" -KEY- -VALUE-"); for (int i = 0; i < myList.Count; i++) { Console.WriteLine(" {0,-6}: {1}", myList.GetKey(i), myList.GetByIndex(i)); } Console.WriteLine(); } } /* This code produces the following output. Results vary depending on the system's culture settings. mySL1 (default): -KEY- -VALUE- first : Ola! FIRST : Hello SECOND: World THIRD : ! mySL2 (case-insensitive comparer): System.ArgumentException: Item has already been added. Key in dictionary: 'FIRST' Key being added: 'first' at System.Collections.SortedList.Add(Object key, Object value) at SamplesSortedList.Main() -KEY- -VALUE- FIRST : Hello SECOND: World THIRD : ! mySL3 (case-insensitive comparer, Turkish culture): -KEY- -VALUE- FIRST : Hello first : Ola! SECOND: World THIRD : ! mySL4 (InvariantCultureIgnoreCase): System.ArgumentException: Item has already been added. Key in dictionary: 'FIRST' Key being added: 'first' at System.Collections.SortedList.Add(Object key, Object value) at SamplesSortedList.Main() -KEY- -VALUE- FIRST : Hello SECOND: World THIRD : ! */

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


SortedList コンストラクタ (IComparer, Int32)
アセンブリ: mscorlib (mscorlib.dll 内)

Dim comparer As IComparer Dim capacity As Integer Dim instance As New SortedList(comparer, capacity)


要素は、指定した IComparer 実装に基づいて並べ替えられます。comparer が null 参照 (Visual Basic では Nothing) の場合、各キーの IComparable 実装が使用されます。したがって、各キーは、SortedList 内の他のキーとの比較を行うことができるように、IComparable インターフェイスを実装する必要があります。
SortedList の容量は、SortedList が保持できる要素数になります。SortedList に要素を追加すると、必要に応じて、内部の配列の再割り当てによって容量が自動的に増加します。
コレクションのサイズを推定できる場合は、初期量を指定すると、SortedList に要素を追加するときに、サイズ変更操作を何度も実行する必要がなくなります。

異なる SortedList コンストラクタを使用してコレクションを作成し、各コレクションの動作の違いを示すコード例を次に示します。
Imports System Imports System.Collections Imports System.Globalization Public Class SamplesSortedList Public Shared Sub Main() ' Create a SortedList using the default comparer. Dim mySL1 As New SortedList( 3 ) Console.WriteLine("mySL1 (default):") mySL1.Add("FIRST", "Hello") mySL1.Add("SECOND", "World") mySL1.Add("THIRD", "!") Try mySL1.Add("first", "Ola!") Catch e As ArgumentException Console.WriteLine(e) End Try PrintKeysAndValues(mySL1) ' Create a SortedList using the specified case-insensitive comparer. Dim mySL2 As New SortedList(New CaseInsensitiveComparer(), 3) Console.WriteLine("mySL2 (case-insensitive comparer):") mySL2.Add("FIRST", "Hello") mySL2.Add("SECOND", "World") mySL2.Add("THIRD", "!") Try mySL2.Add("first", "Ola!") Catch e As ArgumentException Console.WriteLine(e) End Try PrintKeysAndValues(mySL2) ' Create a SortedList using the specified CaseInsensitiveComparer , ' which is based on the Turkish culture (tr-TR), where "I" is not ' the uppercase version of "i". Dim myCul As New CultureInfo("tr-TR") Dim mySL3 As New SortedList(New CaseInsensitiveComparer(myCul), 3) Console.WriteLine("mySL3 (case-insensitive comparer, Turkish culture):") mySL3.Add("FIRST", "Hello") mySL3.Add("SECOND", "World") mySL3.Add("THIRD", "!") Try mySL3.Add("first", "Ola!") Catch e As ArgumentException Console.WriteLine(e) End Try PrintKeysAndValues(mySL3) ' Create a SortedList using the ' StringComparer.InvariantCultureIgnoreCase value. Dim mySL4 As New SortedList( _ StringComparer.InvariantCultureIgnoreCase, 3) Console.WriteLine("mySL4 (InvariantCultureIgnoreCase):") mySL4.Add("FIRST", "Hello") mySL4.Add("SECOND", "World") mySL4.Add("THIRD", "!") Try mySL4.Add("first", "Ola!") Catch e As ArgumentException Console.WriteLine(e) End Try PrintKeysAndValues(mySL4) End Sub 'Main Public Shared Sub PrintKeysAndValues(ByVal myList As SortedList) Console.WriteLine(" -KEY- -VALUE-") Dim i As Integer For i = 0 To myList.Count - 1 Console.WriteLine(" {0,-6}: {1}", _ myList.GetKey(i), myList.GetByIndex(i)) Next i Console.WriteLine() End Sub 'PrintKeysAndValues End Class 'SamplesSortedList 'This code produces the following output. Results vary depending on the system's culture settings. ' 'mySL1 (default): ' -KEY- -VALUE- ' first : Ola! ' FIRST : Hello ' SECOND: World ' THIRD : ! ' 'mySL2 (case-insensitive comparer): 'System.ArgumentException: Item has already been added. Key in dictionary: 'FIRST' Key being added: 'first'' at System.Collections.SortedList.Add(Object key, Object value) ' at SamplesSortedList.Main() ' -KEY- -VALUE- ' FIRST : Hello ' SECOND: World ' THIRD : ! ' 'mySL3 (case-insensitive comparer, Turkish culture): ' -KEY- -VALUE- ' FIRST : Hello ' first : Ola! ' SECOND: World ' THIRD : ! ' 'mySL4 (InvariantCultureIgnoreCase): 'System.ArgumentException: Item has already been added. Key in dictionary: 'FIRST' Key being added: 'first'' at System.Collections.SortedList.Add(Object key, Object value) ' at SamplesSortedList.Main() ' -KEY- -VALUE- ' FIRST : Hello ' SECOND: World ' THIRD : !
using System; using System.Collections; using System.Globalization; public class SamplesSortedList { public static void Main() { // Create a SortedList using the default comparer. SortedList mySL1 = new SortedList( 3 ); Console.WriteLine("mySL1 (default):"); mySL1.Add("FIRST", "Hello"); mySL1.Add("SECOND", "World"); mySL1.Add("THIRD", "!"); try { mySL1.Add("first", "Ola!"); } catch (ArgumentException e) { Console.WriteLine(e); } PrintKeysAndValues(mySL1); // Create a SortedList using the specified case-insensitive comparer. SortedList mySL2 = new SortedList(new CaseInsensitiveComparer(), 3); Console.WriteLine("mySL2 (case-insensitive comparer):"); mySL2.Add("FIRST", "Hello"); mySL2.Add("SECOND", "World"); mySL2.Add("THIRD", "!"); try { mySL2.Add("first", "Ola!"); } catch (ArgumentException e) { Console.WriteLine(e); } PrintKeysAndValues(mySL2); // Create a SortedList using the specified CaseInsensitiveComparer , // which is based on the Turkish culture (tr-TR), where "I" is not // the uppercase version of "i". CultureInfo myCul = new CultureInfo("tr-TR"); SortedList mySL3 = new SortedList(new CaseInsensitiveComparer(myCul), 3); Console.WriteLine( "mySL3 (case-insensitive comparer, Turkish culture):"); mySL3.Add("FIRST", "Hello"); mySL3.Add("SECOND", "World"); mySL3.Add("THIRD", "!"); try { mySL3.Add("first", "Ola!"); } catch (ArgumentException e) { Console.WriteLine(e); } PrintKeysAndValues(mySL3); // Create a SortedList using the // StringComparer.InvariantCultureIgnoreCase value. SortedList mySL4 = new SortedList( StringComparer.InvariantCultureIgnoreCase, 3); Console.WriteLine("mySL4 (InvariantCultureIgnoreCase):"); mySL4.Add("FIRST", "Hello"); mySL4.Add("SECOND", "World"); mySL4.Add("THIRD", "!"); try { mySL4.Add("first", "Ola!"); } catch (ArgumentException e) { Console.WriteLine(e); } PrintKeysAndValues(mySL4); } public static void PrintKeysAndValues(SortedList myList) { Console.WriteLine(" -KEY- -VALUE-"); for (int i = 0; i < myList.Count; i++) { Console.WriteLine(" {0,-6}: {1}", myList.GetKey(i), myList.GetByIndex(i)); } Console.WriteLine(); } } /* This code produces the following output. Results vary depending on the system's culture settings. mySL1 (default): -KEY- -VALUE- first : Ola! FIRST : Hello SECOND: World THIRD : ! mySL2 (case-insensitive comparer): System.ArgumentException: Item has already been added. Key in dictionary: 'FIRST' Key being added: 'first' at System.Collections.SortedList.Add(Object key, Object value) at SamplesSortedList.Main() -KEY- -VALUE- FIRST : Hello SECOND: World THIRD : ! mySL3 (case-insensitive comparer, Turkish culture): -KEY- -VALUE- FIRST : Hello first : Ola! SECOND: World THIRD : ! mySL4 (InvariantCultureIgnoreCase): System.ArgumentException: Item has already been added. Key in dictionary: 'FIRST' Key being added: 'first' at System.Collections.SortedList.Add(Object key, Object value) at SamplesSortedList.Main() -KEY- -VALUE- FIRST : Hello SECOND: World THIRD : ! */

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


SortedList コンストラクタ (IDictionary, IComparer)
アセンブリ: mscorlib (mscorlib.dll 内)



要素は、指定した IComparer 実装に基づいて並べ替えられます。comparer が null 参照 (Visual Basic では Nothing) の場合、各キーの IComparable 実装が使用されます。したがって、各キーは、SortedList 内の他のキーとの比較を行うことができるように、IComparable インターフェイスを実装する必要があります。
Hashtable は、このコンストラクタに渡すことができる IDictionary 実装の一例です。新しい SortedList には、Hashtable で並べ替えられたキーと値のコピーが格納されます。
SortedList の容量は、SortedList が保持できる要素数になります。SortedList に要素を追加すると、必要に応じて、内部の配列の再割り当てによって容量が自動的に増加します。
コレクションのサイズを推定できる場合は、初期量を指定すると、SortedList に要素を追加するときに、サイズ変更操作を何度も実行する必要がなくなります。

異なる SortedList コンストラクタを使用してコレクションを作成し、各コレクションの動作の違いを示すコード例を次に示します。
Imports System Imports System.Collections Imports System.Globalization Public Class SamplesSortedList Public Shared Sub Main() ' Create the dictionary. Dim myHT As New Hashtable() myHT.Add("FIRST", "Hello") myHT.Add("SECOND", "World") myHT.Add("THIRD", "!") ' Create a SortedList using the default comparer. Dim mySL1 As New SortedList(myHT) Console.WriteLine("mySL1 (default):") Try mySL1.Add("first", "Ola!") Catch e As ArgumentException Console.WriteLine(e) End Try PrintKeysAndValues(mySL1) ' Create a SortedList using the specified case-insensitive comparer. Dim mySL2 As New SortedList(myHT, New CaseInsensitiveComparer()) Console.WriteLine("mySL2 (case-insensitive comparer):") Try mySL2.Add("first", "Ola!") Catch e As ArgumentException Console.WriteLine(e) End Try PrintKeysAndValues(mySL2) ' Create a SortedList using the specified CaseInsensitiveComparer , ' which is based on the Turkish culture (tr-TR), where "I" is not ' the uppercase version of "i". Dim myCul As New CultureInfo("tr-TR") Dim mySL3 As New SortedList(myHT, New CaseInsensitiveComparer(myCul)) Console.WriteLine("mySL3 (case-insensitive comparer, Turkish culture):") Try mySL3.Add("first", "Ola!") Catch e As ArgumentException Console.WriteLine(e) End Try PrintKeysAndValues(mySL3) ' Create a SortedList using the ' StringComparer.InvariantCultureIgnoreCase value. Dim mySL4 As New SortedList(myHT, StringComparer.InvariantCultureIgnoreCase) Console.WriteLine("mySL4 (InvariantCultureIgnoreCase):") Try mySL4.Add("first", "Ola!") Catch e As ArgumentException Console.WriteLine(e) End Try PrintKeysAndValues(mySL4) End Sub 'Main Public Shared Sub PrintKeysAndValues(ByVal myList As SortedList) Console.WriteLine(" -KEY- -VALUE-") Dim i As Integer For i = 0 To myList.Count - 1 Console.WriteLine(" {0,-6}: {1}", _ myList.GetKey(i), myList.GetByIndex(i)) Next i Console.WriteLine() End Sub 'PrintKeysAndValues End Class 'SamplesSortedList 'This code produces the following output. Results vary depending on the system's culture settings. ' 'mySL1 (default): ' -KEY- -VALUE- ' first : Ola! ' FIRST : Hello ' SECOND: World ' THIRD : ! ' 'mySL2 (case-insensitive comparer): 'System.ArgumentException: Item has already been added. Key in dictionary: 'FIRST' Key being added: 'first'' at System.Collections.SortedList.Add(Object key, Object value) ' at SamplesSortedList.Main() ' -KEY- -VALUE- ' FIRST : Hello ' SECOND: World ' THIRD : ! ' 'mySL3 (case-insensitive comparer, Turkish culture): ' -KEY- -VALUE- ' FIRST : Hello ' first : Ola! ' SECOND: World ' THIRD : ! ' 'mySL4 (InvariantCultureIgnoreCase): 'System.ArgumentException: Item has already been added. Key in dictionary: 'FIRST' Key being added: 'first'' at System.Collections.SortedList.Add(Object key, Object value) ' at SamplesSortedList.Main() ' -KEY- -VALUE- ' FIRST : Hello ' SECOND: World ' THIRD : !
using System; using System.Collections; using System.Globalization; public class SamplesSortedList { public static void Main() { // Create the dictionary. Hashtable myHT = new Hashtable(); myHT.Add("FIRST", "Hello"); myHT.Add("SECOND", "World"); myHT.Add("THIRD", "!"); // Create a SortedList using the default comparer. SortedList mySL1 = new SortedList(myHT); Console.WriteLine("mySL1 (default):"); try { mySL1.Add("first", "Ola!"); } catch (ArgumentException e) { Console.WriteLine(e); } PrintKeysAndValues(mySL1); // Create a SortedList using the specified case-insensitive comparer. SortedList mySL2 = new SortedList(myHT, new CaseInsensitiveComparer()); Console.WriteLine("mySL2 (case-insensitive comparer):"); try { mySL2.Add("first", "Ola!"); } catch (ArgumentException e) { Console.WriteLine(e); } PrintKeysAndValues(mySL2); // Create a SortedList using the specified CaseInsensitiveComparer , // which is based on the Turkish culture (tr-TR), where "I" is not // the uppercase version of "i". CultureInfo myCul = new CultureInfo("tr-TR"); SortedList mySL3 = new SortedList(myHT, new CaseInsensitiveComparer(myCul)); Console.WriteLine("mySL3 (case-insensitive comparer, Turkish culture):"); try { mySL3.Add("first", "Ola!"); } catch (ArgumentException e) { Console.WriteLine(e); } PrintKeysAndValues(mySL3); // Create a SortedList using the // StringComparer.InvariantCultureIgnoreCase value. SortedList mySL4 = new SortedList( myHT, StringComparer.InvariantCultureIgnoreCase); Console.WriteLine("mySL4 (InvariantCultureIgnoreCase):"); try { mySL4.Add("first", "Ola!"); } catch (ArgumentException e) { Console.WriteLine(e); } PrintKeysAndValues(mySL4); } public static void PrintKeysAndValues(SortedList myList) { Console.WriteLine(" -KEY- -VALUE-"); for (int i = 0; i < myList.Count; i++) { Console.WriteLine(" {0,-6}: {1}", myList.GetKey(i), myList.GetByIndex(i)); } Console.WriteLine(); } } /* This code produces the following output. Results vary depending on the system's culture settings. mySL1 (default): -KEY- -VALUE- first : Ola! FIRST : Hello SECOND: World THIRD : ! mySL2 (case-insensitive comparer): System.ArgumentException: Item has already been added. Key in dictionary: 'FIRST' Key being added: 'first' at System.Collections.SortedList.Add(Object key, Object value) at SamplesSortedList.Main() -KEY- -VALUE- FIRST : Hello SECOND: World THIRD : ! mySL3 (case-insensitive comparer, Turkish culture): -KEY- -VALUE- FIRST : Hello first : Ola! SECOND: World THIRD : ! mySL4 (InvariantCultureIgnoreCase): System.ArgumentException: Item has already been added. Key in dictionary: 'FIRST' Key being added: 'first' at System.Collections.SortedList.Add(Object key, Object value) at SamplesSortedList.Main() -KEY- -VALUE- FIRST : Hello SECOND: World THIRD : ! */

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


SortedList コンストラクタ (IComparer)
アセンブリ: mscorlib (mscorlib.dll 内)


要素は、指定した IComparer 実装に基づいて並べ替えられます。comparer が null 参照 (Visual Basic では Nothing) の場合、各キーの IComparable 実装が使用されます。したがって、各キーは、SortedList 内の他のキーとの比較を行うことができるように、IComparable インターフェイスを実装する必要があります。
SortedList の容量は、SortedList が保持できる要素数になります。SortedList に要素を追加すると、必要に応じて、内部の配列の再割り当てによって容量が自動的に増加します。
コレクションのサイズを推定できる場合は、初期量を指定すると、SortedList に要素を追加するときに、サイズ変更操作を何度も実行する必要がなくなります。

異なる SortedList コンストラクタを使用してコレクションを作成し、各コレクションの動作の違いを示すコード例を次に示します。
Imports System Imports System.Collections Imports System.Globalization Public Class SamplesSortedList Public Shared Sub Main() ' Create a SortedList using the default comparer. Dim mySL1 As New SortedList() Console.WriteLine("mySL1 (default):") mySL1.Add("FIRST", "Hello") mySL1.Add("SECOND", "World") mySL1.Add("THIRD", "!") Try mySL1.Add("first", "Ola!") Catch e As ArgumentException Console.WriteLine(e) End Try PrintKeysAndValues(mySL1) ' Create a SortedList using the specified case-insensitive comparer. Dim mySL2 As New SortedList(New CaseInsensitiveComparer()) Console.WriteLine("mySL2 (case-insensitive comparer):") mySL2.Add("FIRST", "Hello") mySL2.Add("SECOND", "World") mySL2.Add("THIRD", "!") Try mySL2.Add("first", "Ola!") Catch e As ArgumentException Console.WriteLine(e) End Try PrintKeysAndValues(mySL2) ' Create a SortedList using the specified CaseInsensitiveComparer , ' which is based on the Turkish culture (tr-TR), where "I" is not ' the uppercase version of "i". Dim myCul As New CultureInfo("tr-TR") Dim mySL3 As New SortedList(New CaseInsensitiveComparer(myCul)) Console.WriteLine("mySL3 (case-insensitive comparer, Turkish culture):") mySL3.Add("FIRST", "Hello") mySL3.Add("SECOND", "World") mySL3.Add("THIRD", "!") Try mySL3.Add("first", "Ola!") Catch e As ArgumentException Console.WriteLine(e) End Try PrintKeysAndValues(mySL3) ' Create a SortedList using the ' StringComparer.InvariantCultureIgnoreCase value. Dim mySL4 As New SortedList( _ StringComparer.InvariantCultureIgnoreCase) Console.WriteLine("mySL4 (InvariantCultureIgnoreCase):") mySL4.Add("FIRST", "Hello") mySL4.Add("SECOND", "World") mySL4.Add("THIRD", "!") Try mySL4.Add("first", "Ola!") Catch e As ArgumentException Console.WriteLine(e) End Try PrintKeysAndValues(mySL4) End Sub 'Main Public Shared Sub PrintKeysAndValues(ByVal myList As SortedList) Console.WriteLine(" -KEY- -VALUE-") Dim i As Integer For i = 0 To myList.Count - 1 Console.WriteLine(" {0,-6}: {1}", _ myList.GetKey(i), myList.GetByIndex(i)) Next i Console.WriteLine() End Sub 'PrintKeysAndValues End Class 'SamplesSortedList 'This code produces the following output. Results vary depending on the system's culture settings. ' 'mySL1 (default): ' -KEY- -VALUE- ' first : Ola! ' FIRST : Hello ' SECOND: World ' THIRD : ! ' 'mySL2 (case-insensitive comparer): 'System.ArgumentException: Item has already been added. Key in dictionary: 'FIRST' Key being added: 'first'' at System.Collections.SortedList.Add(Object key, Object value) ' at SamplesSortedList.Main() ' -KEY- -VALUE- ' FIRST : Hello ' SECOND: World ' THIRD : ! ' 'mySL3 (case-insensitive comparer, Turkish culture): ' -KEY- -VALUE- ' FIRST : Hello ' first : Ola! ' SECOND: World ' THIRD : ! ' 'mySL4 (InvariantCultureIgnoreCase): 'System.ArgumentException: Item has already been added. Key in dictionary: 'FIRST' Key being added: 'first'' at System.Collections.SortedList.Add(Object key, Object value) ' at SamplesSortedList.Main() ' -KEY- -VALUE- ' FIRST : Hello ' SECOND: World ' THIRD : !
using System; using System.Collections; using System.Globalization; public class SamplesSortedList { public static void Main() { // Create a SortedList using the default comparer. SortedList mySL1 = new SortedList(); Console.WriteLine("mySL1 (default):"); mySL1.Add("FIRST", "Hello"); mySL1.Add("SECOND", "World"); mySL1.Add("THIRD", "!"); try { mySL1.Add("first", "Ola!"); } catch (ArgumentException e) { Console.WriteLine(e); } PrintKeysAndValues(mySL1); // Create a SortedList using the specified case-insensitive comparer. SortedList mySL2 = new SortedList(new CaseInsensitiveComparer()); Console.WriteLine("mySL2 (case-insensitive comparer):"); mySL2.Add("FIRST", "Hello"); mySL2.Add("SECOND", "World"); mySL2.Add("THIRD", "!"); try { mySL2.Add("first", "Ola!"); } catch (ArgumentException e) { Console.WriteLine(e); } PrintKeysAndValues(mySL2); // Create a SortedList using the specified CaseInsensitiveComparer , // which is based on the Turkish culture (tr-TR), where "I" is not // the uppercase version of "i". CultureInfo myCul = new CultureInfo("tr-TR"); SortedList mySL3 = new SortedList(new CaseInsensitiveComparer(myCul)); Console.WriteLine( "mySL3 (case-insensitive comparer, Turkish culture):"); mySL3.Add("FIRST", "Hello"); mySL3.Add("SECOND", "World"); mySL3.Add("THIRD", "!"); try { mySL3.Add("first", "Ola!"); } catch (ArgumentException e) { Console.WriteLine(e); } PrintKeysAndValues(mySL3); // Create a SortedList using the // StringComparer.InvariantCultureIgnoreCase value. SortedList mySL4 = new SortedList( StringComparer.InvariantCultureIgnoreCase); Console.WriteLine("mySL4 (InvariantCultureIgnoreCase):"); mySL4.Add("FIRST", "Hello"); mySL4.Add("SECOND", "World"); mySL4.Add("THIRD", "!"); try { mySL4.Add("first", "Ola!"); } catch (ArgumentException e) { Console.WriteLine(e); } PrintKeysAndValues(mySL4); } public static void PrintKeysAndValues(SortedList myList) { Console.WriteLine(" -KEY- -VALUE-"); for (int i = 0; i < myList.Count; i++) { Console.WriteLine(" {0,-6}: {1}", myList.GetKey(i), myList.GetByIndex(i)); } Console.WriteLine(); } } /* This code produces the following output. Results vary depending on the system's culture settings. mySL1 (default): -KEY- -VALUE- first : Ola! FIRST : Hello SECOND: World THIRD : ! mySL2 (case-insensitive comparer): System.ArgumentException: Item has already been added. Key in dictionary: 'FIRST' Key being added: 'first' at System.Collections.SortedList.Add(Object key, Object value) at SamplesSortedList.Main() -KEY- -VALUE- FIRST : Hello SECOND: World THIRD : ! mySL3 (case-insensitive comparer, Turkish culture): -KEY- -VALUE- FIRST : Hello first : Ola! SECOND: World THIRD : ! mySL4 (InvariantCultureIgnoreCase): System.ArgumentException: Item has already been added. Key in dictionary: 'FIRST' Key being added: 'first' at System.Collections.SortedList.Add(Object key, Object value) at SamplesSortedList.Main() -KEY- -VALUE- FIRST : Hello SECOND: World THIRD : ! */

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


SortedList コンストラクタ

名前 | 説明 |
---|---|
SortedList () | 空で、既定の初期量を備え、既定の IComparer を使用する、SortedList クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
SortedList (ジェネリック IComparer) | 空で、既定の初期量を備え、指定した IComparer を使用する、SortedList クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
SortedList (ジェネリック IDictionary) | 指定した IDictionary からコピーした要素を格納し、コピーした要素の数を格納できるだけの容量を備え、既定の IComparer を使用する、SortedList クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
SortedList (Int32) | 空で、指定した初期量を備え、既定の IComparer を使用する、SortedList クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
SortedList (ジェネリック IDictionary, ジェネリック IComparer) | 指定した IDictionary からコピーした要素を格納し、コピーした要素の数を格納できるだけの容量を備え、指定した IComparer を使用する、SortedList クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
SortedList (Int32, ジェネリック IComparer) | 空で、指定した初期量を備え、指定した IComparer を使用する、SortedList クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |

関連項目
SortedList ジェネリック クラスSortedList メンバ
System.Collections.Generic 名前空間
Comparer.Default プロパティ
IComparable ジェネリック インターフェイス
IComparable インターフェイス
SortedList コンストラクタ (ジェネリック IComparer)
アセンブリ: System (system.dll 内)


SortedList 内のすべてのキーは指定した比較演算子に従って一意である必要があります。
このコンストラクタは、SortedList の初期量として既定値を使用します。初期量を設定するには、SortedList(Int32,ジェネリック IComparer) コンストラクタを使用します。コレクションの最終的なサイズを推定できる場合、初期量を指定すると、SortedList に要素を追加するときにサイズ変更操作を何度も実行する必要がなくなります。

現在のカルチャの大文字小文字を区別しない比較演算子を使って並べ替えられたリストを作成するコード例を次に示します。この例では、小文字のキーを含む要素と大文字のキーを含む要素を合わせて 4 つの要素を追加します。次に、既存のキーとの違いが大文字と小文字の違いだけであるキーを含む要素の追加を試行し、結果の例外をキャッチし、エラー メッセージを表示します。最後に、大文字小文字を区別しない並べ替え順で要素を表示します。
Imports System Imports System.Collections.Generic Public Class Example Public Shared Sub Main() ' Create a new sorted list of strings, with string keys and ' a case-insensitive comparer for the current culture. Dim openWith As New SortedList(Of String, String)( _ StringComparer.CurrentCultureIgnoreCase) ' Add some elements to the list. openWith.Add("txt", "notepad.exe") openWith.Add("bmp", "paint.exe") openWith.Add("DIB", "paint.exe") openWith.Add("rtf", "wordpad.exe") ' Try to add a fifth element with a key that is the same ' except for case; this would be allowed with the default ' comparer. Try openWith.Add("BMP", "paint.exe") Catch ex As ArgumentException Console.WriteLine(vbLf & "BMP is already in the sorted list.") End Try ' List the contents of the sorted list. Console.WriteLine() For Each kvp As KeyValuePair(Of String, String) In openWith Console.WriteLine("Key = {0}, Value = {1}", _ kvp.Key, kvp.Value) Next kvp End Sub End Class ' This code example produces the following output: ' 'BMP is already in the sorted list. ' 'Key = bmp, Value = paint.exe 'Key = DIB, Value = paint.exe 'Key = rtf, Value = wordpad.exe 'Key = txt, Value = notepad.exe
using System; using System.Collections.Generic; public class Example { public static void Main() { // Create a new sorted list of strings, with string keys and // a case-insensitive comparer for the current culture. SortedList<string, string> openWith = new SortedList<string, string>( StringComparer.CurrentCultureIgnoreCase); // Add some elements to the list. openWith.Add("txt", "notepad.exe"); openWith.Add("bmp", "paint.exe"); openWith.Add("DIB", "paint.exe"); openWith.Add("rtf", "wordpad.exe"); // Try to add a fifth element with a key that is the same // except for case; this would be allowed with the default // comparer. try { openWith.Add("BMP", "paint.exe"); } catch (ArgumentException) { Console.WriteLine("\nBMP is already in the sorted list."); } // List the contents of the sorted list. Console.WriteLine(); foreach( KeyValuePair<string, string> kvp in openWith ) { Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value); } } } /* This code example produces the following output: BMP is already in the sorted list. Key = bmp, Value = paint.exe Key = DIB, Value = paint.exe Key = rtf, Value = wordpad.exe Key = txt, Value = notepad.exe */

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


SortedList ジェネリック クラス
SortedList メンバ
System.Collections.Generic 名前空間
IComparer ジェネリック インターフェイス
Comparer.Default プロパティ
IComparable ジェネリック インターフェイス
IComparable インターフェイス
SortedList コンストラクタ (ジェネリック IDictionary)
アセンブリ: System (system.dll 内)

Public Sub New ( _ dictionary As IDictionary(Of TKey, TValue) _ )
Dim dictionary As IDictionary(Of TKey, TValue) Dim instance As New SortedList(Of TKey, TValue)(dictionary)
public SortedList ( IDictionary<TKey,TValue> dictionary )
public: SortedList ( IDictionary<TKey, TValue>^ dictionary )
public SortedList ( IDictionary<TKey,TValue> dictionary )
public function SortedList ( dictionary : IDictionary<TKey,TValue> )

例外の種類 | 条件 |
---|---|
ArgumentNullException | dictionary が null 参照 (Visual Basic では Nothing) です。 |
ArgumentException |

SortedList 内のすべてのキーは、既定の比較演算子に従って一意である必要があります。同様に、元の dictionary 内のすべてのキーも、既定の比較演算子に従って一意である必要があります。
新しい SortedList の容量は、dictionary 内の要素数に設定されるので、リストの作成時にサイズの変更は行われません。
このコンストラクタは、TKey の既定の比較演算子を使用します。比較演算子を指定するには、SortedList(ジェネリック IDictionary,ジェネリック IComparer) コンストラクタを使用します。既定の比較演算子 Comparer.Default は、キーの型 TKey が System.IComparable を実装し、利用可能な場合はその実装を使用するかどうかをチェックします。それ以外の場合は、Comparer.Default によって、キーの型 TKey が System.IComparable を実装するかどうかをチェックします。キーの型 TKey がいずれのインターフェイスも実装しない場合は、comparer パラメータを受け取るコンストラクタ オーバーロードの System.Collections.Generic.IComparer 実装を指定できます。
dictionary のデータが並べ替え済みの場合、このコンストラクタは O(n) 操作です (n は dictionary 内の要素数)。そうでない場合は O(n*n) 操作です。

Dictionary を SortedList(ジェネリック IDictionary) コンストラクタに渡すことにより、SortedList を使用して、Dictionary 内の情報の並べ替えられたコピーを作成する方法を次のコード例に示します。
Imports System Imports System.Collections.Generic Public Class Example Public Shared Sub Main() ' Create a new Dictionary of strings, with string ' keys. Dim openWith As New Dictionary(Of String, String) ' Add some elements to the dictionary. openWith.Add("txt", "notepad.exe") openWith.Add("bmp", "paint.exe") openWith.Add("dib", "paint.exe") openWith.Add("rtf", "wordpad.exe") ' Create a SortedList of strings with string keys, ' and initialize it with the contents of the Dictionary. Dim copy As New SortedList(Of String, String)(openWith) ' List the sorted contents of the copy. Console.WriteLine() For Each kvp As KeyValuePair(Of String, String) In copy Console.WriteLine("Key = {0}, Value = {1}", _ kvp.Key, kvp.Value) Next kvp End Sub End Class ' This code example produces the following output: ' 'Key = bmp, Value = paint.exe 'Key = dib, Value = paint.exe 'Key = rtf, Value = wordpad.exe 'Key = txt, Value = notepad.exe
using System; using System.Collections.Generic; public class Example { public static void Main() { // Create a new Dictionary of strings, with string keys. // Dictionary<string, string> openWith = new Dictionary<string, string>(); // Add some elements to the dictionary. openWith.Add("txt", "notepad.exe"); openWith.Add("bmp", "paint.exe"); openWith.Add("dib", "paint.exe"); openWith.Add("rtf", "wordpad.exe"); // Create a SortedList of strings with string keys, // and initialize it with the contents of the Dictionary. SortedList<string, string> copy = new SortedList<string, string>(openWith); // List the contents of the copy. Console.WriteLine(); foreach( KeyValuePair<string, string> kvp in copy ) { Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value); } } } /* This code example produces the following output: Key = bmp, Value = paint.exe Key = dib, Value = paint.exe Key = rtf, Value = wordpad.exe Key = txt, Value = notepad.exe */

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


SortedList ジェネリック クラス
SortedList メンバ
System.Collections.Generic 名前空間
IDictionary ジェネリック インターフェイス
Comparer.Default プロパティ
IComparable ジェネリック インターフェイス
IComparable インターフェイス
SortedList コンストラクタ (Int32)
アセンブリ: System (system.dll 内)



SortedList 内のすべてのキーは既定の比較演算子に従って一意である必要があります。
SortedList の容量は、サイズ変更前に SortedList が保持できる要素数になります。SortedList に要素を追加すると、必要に応じて、内部の配列の再割り当てによって容量が自動的に増加します。
コレクションのサイズを推定できる場合は、初期量を指定すると、SortedList に要素を追加するときに、サイズ変更操作を何度も実行する必要がなくなります。
容量を減らすには、TrimExcess を呼び出すか、Capacity プロパティを明示的に設定します。容量を減らすと、メモリの再割り当てが行われ、SortedList 内のすべての要素がコピーされます。
このコンストラクタは、TKey の既定の比較演算子を使用します。比較演算子を指定するには、SortedList(Int32,ジェネリック IComparer) コンストラクタを使用します。既定の比較演算子 Comparer.Default は、キーの型 TKey が System.IComparable を実装し、利用可能な場合はその実装を使用するかどうかをチェックします。それ以外の場合は、Comparer.Default によって、キーの型 TKey が System.IComparable を実装するかどうかをチェックします。キーの型 TKey がいずれのインターフェイスも実装しない場合は、comparer パラメータを受け取るコンストラクタ オーバーロードの System.Collections.Generic.IComparer 実装を指定できます。

並べ替えられたリストを初期量 4 で作成し、4 つのエントリを設定するコード例を次に示します。
Imports System Imports System.Collections.Generic Public Class Example Public Shared Sub Main() ' Create a new sorted list of strings, with string keys and ' an initial capacity of 4. Dim openWith As New SortedList(Of String, String)(4) ' Add 4 elements to the list. openWith.Add("txt", "notepad.exe") openWith.Add("bmp", "paint.exe") openWith.Add("dib", "paint.exe") openWith.Add("rtf", "wordpad.exe") ' List the contents of the sorted list. Console.WriteLine() For Each kvp As KeyValuePair(Of String, String) In openWith Console.WriteLine("Key = {0}, Value = {1}", _ kvp.Key, kvp.Value) Next kvp End Sub End Class ' This code example produces the following output: ' 'Key = bmp, Value = paint.exe 'Key = dib, Value = paint.exe 'Key = rtf, Value = wordpad.exe 'Key = txt, Value = notepad.exe
using System; using System.Collections.Generic; public class Example { public static void Main() { // Create a new sorted list of strings, with string keys and // an initial capacity of 4. SortedList<string, string> openWith = new SortedList<string, string>(4); // Add 4 elements to the list. openWith.Add("txt", "notepad.exe"); openWith.Add("bmp", "paint.exe"); openWith.Add("dib", "paint.exe"); openWith.Add("rtf", "wordpad.exe"); // List the contents of the sorted list. Console.WriteLine(); foreach( KeyValuePair<string, string> kvp in openWith ) { Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value); } } } /* This code example produces the following output: Key = bmp, Value = paint.exe Key = dib, Value = paint.exe Key = rtf, Value = wordpad.exe Key = txt, Value = notepad.exe */

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


SortedList ジェネリック クラス
SortedList メンバ
System.Collections.Generic 名前空間
Capacity
Comparer.Default プロパティ
IComparable ジェネリック インターフェイス
IComparable インターフェイス
SortedList コンストラクタ (ジェネリック IDictionary, ジェネリック IComparer)
アセンブリ: System (system.dll 内)

Public Sub New ( _ dictionary As IDictionary(Of TKey, TValue), _ comparer As IComparer(Of TKey) _ )
Dim dictionary As IDictionary(Of TKey, TValue) Dim comparer As IComparer(Of TKey) Dim instance As New SortedList(Of TKey, TValue)(dictionary, comparer)
public SortedList ( IDictionary<TKey,TValue> dictionary, IComparer<TKey> comparer )
public: SortedList ( IDictionary<TKey, TValue>^ dictionary, IComparer<TKey>^ comparer )
public SortedList ( IDictionary<TKey,TValue> dictionary, IComparer<TKey> comparer )
public function SortedList ( dictionary : IDictionary<TKey,TValue>, comparer : IComparer<TKey> )

例外の種類 | 条件 |
---|---|
ArgumentNullException | dictionary が null 参照 (Visual Basic では Nothing) です。 |
ArgumentException |

SortedList 内のすべてのキーは、指定した比較演算子に従って一意である必要があります。同様に、元の dictionary 内のすべてのキーも、指定した比較演算子に従って一意である必要があります。
新しい SortedList の容量は、dictionary 内の要素数に設定されるので、リストの作成時にサイズの変更は行われません。
dictionary のデータが並べ替え済みの場合、このコンストラクタは O(n) 操作です (n は dictionary 内の要素数)。そうでない場合は O(n*n) 操作です。

Dictionary を SortedList(ジェネリック IDictionary,ジェネリック IComparer) コンストラクタに渡すことにより、SortedList を使用して、大文字小文字を区別しない Dictionary 内の情報の、大文字小文字を区別せずに並べ替えられたコピーを作成する方法を次のコード例に示します。この例では、現在のカルチャの大文字小文字を区別しない比較演算子が使用されます。
Imports System Imports System.Collections.Generic Public Class Example Public Shared Sub Main() ' Create a new Dictionary of strings, with string keys and ' a case-insensitive equality comparer for the current ' culture. Dim openWith As New Dictionary(Of String, String)( _ StringComparer.CurrentCultureIgnoreCase) ' Add some elements to the dictionary. openWith.Add("txt", "notepad.exe") openWith.Add("Bmp", "paint.exe") openWith.Add("DIB", "paint.exe") openWith.Add("rtf", "wordpad.exe") ' Create a SortedList of strings with string keys and a ' case-insensitive equality comparer for the current culture , ' and initialize it with the contents of the Dictionary. Dim copy As New SortedList(Of String, String)(openWith, _ StringComparer.CurrentCultureIgnoreCase) ' List the sorted contents of the copy. Console.WriteLine() For Each kvp As KeyValuePair(Of String, String) In copy Console.WriteLine("Key = {0}, Value = {1}", _ kvp.Key, kvp.Value) Next kvp End Sub End Class ' This code example produces the following output: ' 'Key = Bmp, Value = paint.exe 'Key = DIB, Value = paint.exe 'Key = rtf, Value = wordpad.exe 'Key = txt, Value = notepad.exe
using System; using System.Collections.Generic; public class Example { public static void Main() { // Create a new Dictionary of strings, with string keys and // a case-insensitive equality comparer for the current // culture. Dictionary<string, string> openWith = new Dictionary<string, string> (StringComparer.CurrentCultureIgnoreCase); // Add some elements to the dictionary. openWith.Add("txt", "notepad.exe"); openWith.Add("Bmp", "paint.exe"); openWith.Add("DIB", "paint.exe"); openWith.Add("rtf", "wordpad.exe"); // Create a SortedList of strings with string keys and a // case-insensitive equality comparer for the current culture , // and initialize it with the contents of the Dictionary. SortedList<string, string> copy = new SortedList<string, string>(openWith, StringComparer.CurrentCultureIgnoreCase); // List the sorted contents of the copy. Console.WriteLine(); foreach( KeyValuePair<string, string> kvp in copy ) { Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value); } } } /* This code example produces the following output: Key = Bmp, Value = paint.exe Key = DIB, Value = paint.exe Key = rtf, Value = wordpad.exe Key = txt, Value = notepad.exe */

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


SortedList ジェネリック クラス
SortedList メンバ
System.Collections.Generic 名前空間
IDictionary ジェネリック インターフェイス
IComparer ジェネリック インターフェイス
Comparer.Default プロパティ
IComparable ジェネリック インターフェイス
IComparable インターフェイス
SortedList ジェネリック クラス
アセンブリ: System (system.dll 内)

<SerializableAttribute> _ <ComVisibleAttribute(False)> _ Public Class SortedList(Of TKey, TValue) Implements IDictionary(Of TKey, TValue), ICollection(Of KeyValuePair(Of TKey, TValue)), _ IEnumerable(Of KeyValuePair(Of TKey, TValue)), IDictionary, ICollection, _ IEnumerable
[SerializableAttribute] [ComVisibleAttribute(false)] public class SortedList<TKey,TValue> : IDictionary<TKey,TValue>, ICollection<KeyValuePair<TKey,TValue>>, IEnumerable<KeyValuePair<TKey,TValue>>, IDictionary, ICollection, IEnumerable
[SerializableAttribute] [ComVisibleAttribute(false)] generic<typename TKey, typename TValue> public ref class SortedList : IDictionary<TKey, TValue>, ICollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, IDictionary, ICollection, IEnumerable

SortedList ジェネリック クラスは、O(log n) 取得を使用するバイナリ サーチ ツリーです。n は、ディクショナリ内の要素数を示します。この点で、これは SortedDictionary ジェネリック クラスに似ています。この 2 つのクラスには、同じようなオブジェクト モデルがあり、どちらも O(log n) 取得を備えています。この 2 つのクラスの違いは、メモリの使用方法と、挿入および削除の速度です。
-
SortedDictionary には、並べ替えられていないデータ用の高速な挿入操作および削除操作があります。その計算量は、SortedList が O(n) であるのに対して、O(log n) となります。
-
並べ替えられたデータから一度にすべてのデータを取り込む場合、SortedList の方が SortedDictionary よりも高速です。
SortedDictionary クラスと SortedList クラスの違いとして、SortedList がキーと値の効率的なインデックスによる取得をサポートしていることも挙げられます。これには、Keys プロパティおよび Values プロパティによって返されるコレクションが使用されます。リストはキーと値の内部配列の単なるラッパーなので、プロパティへのアクセス時にリストを再生成する必要はありません。Values プロパティを使用して、文字列の並べ替えられたリストの値をインデックスで取得するコード例を次に示します。
SortedList は、キーで並べ替えられた、キー/値ペアの配列として実装されています。各要素は、KeyValuePair オブジェクトとして取得できます。
キー オブジェクトは、SortedList でキーとして使用されている間は不変であることが必要です。SortedList 内のすべてのキーは一意である必要があります。リストの値の型 TValue が参照型である場合、キーを null 参照 (Visual Basic では Nothing) にすることはできませんが、値を null 参照 (Visual Basic では Nothing) にすることはできます。
SortedList は、並べ替えおよび比較の実行のために比較演算子の実装を必要とします。既定の比較演算子 Comparer.Default は、キーの型 TKey が System.IComparable を実装し、利用可能な場合はその実装を使用するかどうかをチェックします。それ以外の場合は、Comparer.Default によって、キーの型 TKey が System.IComparable を実装するかどうかをチェックします。キーの型 TKey がいずれのインターフェイスも実装しない場合は、comparer パラメータを受け取るコンストラクタ オーバーロードの System.Collections.Generic.IComparer 実装を指定できます。
SortedList の容量は、SortedList が保持できる要素数になります。この実装では、SortedList の既定の初期量は 16 ですが、この既定値は将来の .NET Framework のバージョンで変更される可能性があります。SortedList に要素を追加すると、必要に応じて、内部の配列の再割り当てによって容量が自動的に増加します。容量を減らすには、TrimExcess を呼び出すか、Capacity プロパティを明示的に設定します。容量を減らすと、メモリの再割り当てが行われ、SortedList 内のすべての要素がコピーされます。
C# 言語の foreach ステートメント (C++ の場合は for each、Visual Basic の場合は For Each) には、コレクション内の要素の型が必要です。SortedList の要素はキー/値ペアであるため、要素の型は、キーの型や値の型にはなりません。その代わり、要素の型は KeyValuePair になります。次に例を示します。
foreach ステートメントは、列挙子のラッパーです。これは、コレクションからの読み取りだけを許可し、コレクションへの書き込みを防ぎます。

文字列キーを含む文字列の空の SortedList を作成し、Add メソッドを使用していくつかの要素を追加するコード例を次に示します。この例では、重複するキーを追加しようとすると、Add メソッドが ArgumentException をスローすることを示します。
この例では、Item プロパティ (C# ではインデクサ) を使用して値を取得し、要求されたキーが存在しないときに KeyNotFoundException がスローされる例を示し、またキーに関連付けられた値を置き換えることができることも示します。
この例では、プログラムが並べ替えられたリストにないキー値を頻繁に試行する必要がある場合に、より効率的に値を取得する方法として TryGetValue メソッドを使用する方法、および Add メソッドを呼び出す前にキーが存在するかどうかをテストするために ContainsKey メソッドを使用する方法を示します。
この例では、並べ替えられたリストのキーと値を列挙する方法、および Keys プロパティと Values プロパティを使用してキーと値のみを列挙する方法を示します。
Imports System Imports System.Collections.Generic Public Class Example Public Shared Sub Main() ' Create a new sorted list of strings, with string ' keys. Dim openWith As New SortedList(Of String, String) ' Add some elements to the list. There are no ' duplicate keys, but some of the values are duplicates. openWith.Add("txt", "notepad.exe") openWith.Add("bmp", "paint.exe") openWith.Add("dib", "paint.exe") openWith.Add("rtf", "wordpad.exe") ' The Add method throws an exception if the new key is ' already in the list. Try openWith.Add("txt", "winword.exe") Catch Console.WriteLine("An element with Key = ""txt"" already exists.") End Try ' The Item property is the default property, so you ' can omit its name when accessing elements. Console.WriteLine("For key = ""rtf"", value = {0}.", _ openWith("rtf")) ' The default Item property can be used to change the value ' associated with a key. openWith("rtf") = "winword.exe" Console.WriteLine("For key = ""rtf"", value = {0}.", _ openWith("rtf")) ' If a key does not exist, setting the default Item property ' for that key adds a new key/value pair. openWith("doc") = "winword.exe" ' The default Item property throws an exception if the requested ' key is not in the list. Try Console.WriteLine("For key = ""tif"", value = {0}.", _ openWith("tif")) Catch Console.WriteLine("Key = ""tif"" is not found.") End Try ' When a program often has to try keys that turn out not to ' be in the list, TryGetValue can be a more efficient ' way to retrieve values. Dim value As String = "" If openWith.TryGetValue("tif", value) Then Console.WriteLine("For key = ""tif"", value = {0}.", value) Else Console.WriteLine("Key = ""tif"" is not found.") End If ' ContainsKey can be used to test keys before inserting ' them. If Not openWith.ContainsKey("ht") Then openWith.Add("ht", "hypertrm.exe") Console.WriteLine("Value added for key = ""ht"": {0}", _ openWith("ht")) End If ' When you use foreach to enumerate list elements, ' the elements are retrieved as KeyValuePair objects. Console.WriteLine() For Each kvp As KeyValuePair(Of String, String) In openWith Console.WriteLine("Key = {0}, Value = {1}", _ kvp.Key, kvp.Value) Next kvp ' To get the values alone, use the Values property. Dim ilistValues As IList(Of String) = openWith.Values ' The elements of the list are strongly typed with the ' type that was specified for the SortedList values. Console.WriteLine() For Each s As String In ilistValues Console.WriteLine("Value = {0}", s) Next s ' The Values property is an efficient way to retrieve ' values by index. Console.WriteLine(vbLf & "Indexed retrieval using the " & _ "Values property: Values(2) = {0}", openWith.Values(2)) ' To get the keys alone, use the Keys property. Dim ilistKeys As IList(Of String) = openWith.Keys ' The elements of the list are strongly typed with the ' type that was specified for the SortedList keys. Console.WriteLine() For Each s As String In ilistKeys Console.WriteLine("Key = {0}", s) Next s ' The Keys property is an efficient way to retrieve ' keys by index. Console.WriteLine(vbLf & "Indexed retrieval using the " & _ "Keys property: Keys(2) = {0}", openWith.Keys(2)) ' Use the Remove method to remove a key/value pair. Console.WriteLine(vbLf + "Remove(""doc"")") openWith.Remove("doc") If Not openWith.ContainsKey("doc") Then Console.WriteLine("Key ""doc"" is not found.") End If End Sub End Class ' This code example produces the following output: ' 'An element with Key = "txt" already exists. 'For key = "rtf", value = wordpad.exe. 'For key = "rtf", value = winword.exe. 'Key = "tif" is not found. 'Key = "tif" is not found. 'Value added for key = "ht": hypertrm.exe ' 'Key = bmp, Value = paint.exe 'Key = dib, Value = paint.exe 'Key = doc, Value = winword.exe 'Key = ht, Value = hypertrm.exe 'Key = rtf, Value = winword.exe 'Key = txt, Value = notepad.exe ' 'Value = paint.exe 'Value = paint.exe 'Value = winword.exe 'Value = hypertrm.exe 'Value = winword.exe 'Value = notepad.exe ' 'Indexed retrieval using the Values property: Values(2) = winword.exe ' 'Key = bmp 'Key = dib 'Key = doc 'Key = ht 'Key = rtf 'Key = txt ' 'Indexed retrieval using the Keys property: Keys(2) = doc ' 'Remove("doc") 'Key "doc" is not found. '
using System; using System.Collections.Generic; public class Example { public static void Main() { // Create a new sorted list of strings, with string // keys. SortedList<string, string> openWith = new SortedList<string, string>(); // Add some elements to the list. There are no // duplicate keys, but some of the values are duplicates. openWith.Add("txt", "notepad.exe"); openWith.Add("bmp", "paint.exe"); openWith.Add("dib", "paint.exe"); openWith.Add("rtf", "wordpad.exe"); // The Add method throws an exception if the new key is // already in the list. try { openWith.Add("txt", "winword.exe"); } catch (ArgumentException) { Console.WriteLine("An element with Key = \"txt\" already exists."); } // The Item property is another name for the indexer, so you // can omit its name when accessing elements. Console.WriteLine("For key = \"rtf\", value = {0}.", openWith["rtf"]); // The indexer can be used to change the value associated // with a key. openWith["rtf"] = "winword.exe"; Console.WriteLine("For key = \"rtf\", value = {0}.", openWith["rtf"]); // If a key does not exist, setting the indexer for that key // adds a new key/value pair. openWith["doc"] = "winword.exe"; // The indexer throws an exception if the requested key is // not in the list. try { Console.WriteLine("For key = \"tif\", value = {0}.", openWith["tif"]); } catch (KeyNotFoundException) { Console.WriteLine("Key = \"tif\" is not found."); } // When a program often has to try keys that turn out not to // be in the list, TryGetValue can be a more efficient // way to retrieve values. string value = ""; if (openWith.TryGetValue("tif", out value)) { Console.WriteLine("For key = \"tif\", value = {0}.", value); } else { Console.WriteLine("Key = \"tif\" is not found."); } // ContainsKey can be used to test keys before inserting // them. if (!openWith.ContainsKey("ht")) { openWith.Add("ht", "hypertrm.exe"); Console.WriteLine("Value added for key = \"ht\": {0}", openWith["ht"]); } // When you use foreach to enumerate list elements, // the elements are retrieved as KeyValuePair objects. Console.WriteLine(); foreach( KeyValuePair<string, string> kvp in openWith ) { Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value); } // To get the values alone, use the Values property. IList<string> ilistValues = openWith.Values; // The elements of the list are strongly typed with the // type that was specified for the SorteList values. Console.WriteLine(); foreach( string s in ilistValues ) { Console.WriteLine("Value = {0}", s); } // The Values property is an efficient way to retrieve // values by index. Console.WriteLine("\nIndexed retrieval using the Values " + "property: Values[2] = {0}", openWith.Values[2]); // To get the keys alone, use the Keys property. IList<string> ilistKeys = openWith.Keys; // The elements of the list are strongly typed with the // type that was specified for the SortedList keys. Console.WriteLine(); foreach( string s in ilistKeys ) { Console.WriteLine("Key = {0}", s); } // The Keys property is an efficient way to retrieve // keys by index. Console.WriteLine("\nIndexed retrieval using the Keys " + "property: Keys[2] = {0}", openWith.Keys[2]); // Use the Remove method to remove a key/value pair. Console.WriteLine("\nRemove(\"doc\")"); openWith.Remove("doc"); if (!openWith.ContainsKey("doc")) { Console.WriteLine("Key \"doc\" is not found."); } } } /* This code example produces the following output: An element with Key = "txt" already exists. For key = "rtf", value = wordpad.exe. For key = "rtf", value = winword.exe. Key = "tif" is not found. Key = "tif" is not found. Value added for key = "ht": hypertrm.exe Key = bmp, Value = paint.exe Key = dib, Value = paint.exe Key = doc, Value = winword.exe Key = ht, Value = hypertrm.exe Key = rtf, Value = winword.exe Key = txt, Value = notepad.exe Value = paint.exe Value = paint.exe Value = winword.exe Value = hypertrm.exe Value = winword.exe Value = notepad.exe Indexed retrieval using the Values property: Values[2] = winword.exe Key = bmp Key = dib Key = doc Key = ht Key = rtf Key = txt Indexed retrieval using the Keys property: Keys[2] = doc Remove("doc") Key "doc" is not found. */

System.Collections.Generic.SortedList

この型の public static (Visual Basic では Shared) メンバは、スレッド セーフです。すべてのインスタンス メンバがスレッド セーフになるかどうかは保証されていません。
コレクションが変更されない限り、SortedList では、複数の読み込み操作が同時に発生しても問題ありません。ただし、コレクションの列挙処理は、本質的にはスレッド セーフな処理ではありません。すべての列挙処理が終わるまでコレクションをロックすることにより、列挙処理でのスレッド セーフを確保できます。コレクションに対し複数のスレッドがアクセスして読み取りや書き込みを行うことができるようにするには、独自に同期化を実装する必要があります。

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


SortedList メンバ
System.Collections.Generic 名前空間
IDictionary ジェネリック インターフェイス
Dictionary ジェネリック クラス
SortedDictionary ジェネリック クラス
KeyValuePair ジェネリック構造体
IComparer ジェネリック インターフェイス
SortedList プロパティ



関連項目
SortedList ジェネリック クラスSystem.Collections.Generic 名前空間
IDictionary ジェネリック インターフェイス
Dictionary ジェネリック クラス
SortedDictionary ジェネリック クラス
KeyValuePair ジェネリック構造体
IComparer ジェネリック インターフェイス
SortedList プロパティ
SortedList メソッド

名前 | 説明 | |
---|---|---|
![]() | Add | 指定したキーおよび値を持つ要素を SortedList に追加します。 |
![]() | Clear | SortedList からすべての要素を削除します。 |
![]() | ContainsKey | SortedList に特定のキーが格納されているかどうかを判断します。 |
![]() | ContainsValue | SortedList に特定の値が格納されているかどうかを判断します。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetEnumerator | SortedList を反復処理する列挙子を返します。 |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | IndexOfKey | 指定したキーを検索し、SortedList 全体内でそのキーが見つかった位置の 0 から始まるインデックスを返します。 |
![]() | IndexOfValue | 指定した値を検索し、SortedList 全体内で最初に見つかった位置の 0 から始まるインデックスを返します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | Remove | 指定したキーを持つ要素を SortedList から削除します。 |
![]() | RemoveAt | SortedList の指定したインデックスにある要素を削除します。 |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |
![]() | TrimExcess | SortedList 内にある実際の要素数が現在の容量の 90% 未満の場合は、容量をその数に設定します。 |
![]() | TryGetValue | 指定したキーに関連付けられている値を取得します。 |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>.Add | ICollection に、キー/値ペアを追加します。 |
![]() | System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>.Contains | ICollection に特定の要素が格納されているかどうかを判断します。 |
![]() | System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>.CopyTo | ICollection の要素を Array にコピーします。Array の特定のインデックスからコピーが開始されます。 |
![]() | System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>.Remove | ICollection 内で最初に見つかった特定のキー/値ペアを削除します。 |
![]() | System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey,TValue>>.GetEnumerator | コレクションを反復処理する列挙子を返します。 |
![]() | System.Collections.ICollection.CopyTo | ICollection の要素を Array にコピーします。Array の特定のインデックスからコピーが開始されます。 |
![]() | System.Collections.IDictionary.Add | 指定したキーおよび値を持つ要素を IDictionary に追加します。 |
![]() | System.Collections.IDictionary.Contains | 指定したキーの要素が IDictionary に格納されているかどうかを確認します。 |
![]() | System.Collections.IDictionary.GetEnumerator | IDictionary の IDictionaryEnumerator を返します。 |
![]() | System.Collections.IDictionary.Remove | 指定したキーを持つ要素を IDictionary から削除します。 |
![]() | System.Collections.IEnumerable.GetEnumerator | コレクションを反復処理する列挙子を返します。 |

関連項目
SortedList ジェネリック クラスSystem.Collections.Generic 名前空間
IDictionary ジェネリック インターフェイス
Dictionary ジェネリック クラス
SortedDictionary ジェネリック クラス
KeyValuePair ジェネリック構造体
IComparer ジェネリック インターフェイス
SortedList メソッド

名前 | 説明 | |
---|---|---|
![]() | Add | 指定したキーおよび値を持つ要素を SortedList に追加します。 |
![]() | Clear | SortedList からすべての要素を削除します。 |
![]() | Clone | SortedList の簡易コピーを作成します。 |
![]() | Contains | SortedList に特定のキーが格納されているかどうかを判断します。 |
![]() | ContainsKey | SortedList に特定のキーが格納されているかどうかを判断します。 |
![]() | ContainsValue | SortedList に特定の値が格納されているかどうかを判断します。 |
![]() | CopyTo | 1 次元の Array インスタンスの指定したインデックスに SortedList の要素をコピーします。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetByIndex | SortedList の指定したインデックスにある値を取得します。 |
![]() | GetEnumerator | SortedList を反復処理する IDictionaryEnumerator を返します。 |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetKey | SortedList の指定したインデックスにあるキーを取得します。 |
![]() | GetKeyList | SortedList 内のキーを取得します。 |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | GetValueList | SortedList 内の値を取得します。 |
![]() | IndexOfKey | SortedList 内の指定したキーの、0 から始まるインデックス番号を返します。 |
![]() | IndexOfValue | SortedList 内にある指定した値のうち、最初に出現する値の、0 から始まるインデックス番号を返します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | Remove | 指定したキーを持つ要素を SortedList から削除します。 |
![]() | RemoveAt | SortedList の指定したインデックスにある要素を削除します。 |
![]() | SetByIndex | SortedList の特定のインデックスにある値を置換します。 |
![]() | Synchronized | SortedList 用の同期された (スレッド セーフな) ラッパーを返します。 |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |
![]() | TrimToSize | 容量を SortedList 内にある実際の要素数に設定します。 |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |


SortedList メンバ
関連付けられた IComparer 実装に基づいてキーで並べ替えられた、キー/値ペアのコレクションを表します。
SortedList ジェネリック型で公開されるメンバを以下の表に示します。



名前 | 説明 | |
---|---|---|
![]() | Add | 指定したキーおよび値を持つ要素を SortedList に追加します。 |
![]() | Clear | SortedList からすべての要素を削除します。 |
![]() | ContainsKey | SortedList に特定のキーが格納されているかどうかを判断します。 |
![]() | ContainsValue | SortedList に特定の値が格納されているかどうかを判断します。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetEnumerator | SortedList を反復処理する列挙子を返します。 |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | IndexOfKey | 指定したキーを検索し、SortedList 全体内でそのキーが見つかった位置の 0 から始まるインデックスを返します。 |
![]() | IndexOfValue | 指定した値を検索し、SortedList 全体内で最初に見つかった位置の 0 から始まるインデックスを返します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | Remove | 指定したキーを持つ要素を SortedList から削除します。 |
![]() | RemoveAt | SortedList の指定したインデックスにある要素を削除します。 |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |
![]() | TrimExcess | SortedList 内にある実際の要素数が現在の容量の 90% 未満の場合は、容量をその数に設定します。 |
![]() | TryGetValue | 指定したキーに関連付けられている値を取得します。 |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>.Add | ICollection に、キー/値ペアを追加します。 |
![]() | System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>.Contains | ICollection に特定の要素が格納されているかどうかを判断します。 |
![]() | System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>.CopyTo | ICollection の要素を Array にコピーします。Array の特定のインデックスからコピーが開始されます。 |
![]() | System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>.Remove | ICollection 内で最初に見つかった特定のキー/値ペアを削除します。 |
![]() | System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey,TValue>>.GetEnumerator | コレクションを反復処理する列挙子を返します。 |
![]() | System.Collections.ICollection.CopyTo | ICollection の要素を Array にコピーします。Array の特定のインデックスからコピーが開始されます。 |
![]() | System.Collections.IDictionary.Add | 指定したキーおよび値を持つ要素を IDictionary に追加します。 |
![]() | System.Collections.IDictionary.Contains | 指定したキーの要素が IDictionary に格納されているかどうかを確認します。 |
![]() | System.Collections.IDictionary.GetEnumerator | IDictionary の IDictionaryEnumerator を返します。 |
![]() | System.Collections.IDictionary.Remove | 指定したキーを持つ要素を IDictionary から削除します。 |
![]() | System.Collections.IEnumerable.GetEnumerator | コレクションを反復処理する列挙子を返します。 |
![]() | System.Collections.IDictionary.Values | IDictionary 内の値を格納している ICollection を取得します。 |

関連項目
SortedList ジェネリック クラスSystem.Collections.Generic 名前空間
IDictionary ジェネリック インターフェイス
Dictionary ジェネリック クラス
SortedDictionary ジェネリック クラス
KeyValuePair ジェネリック構造体
IComparer ジェネリック インターフェイス
SortedList メンバ
キーによって並べ替えられ、キーとインデックスを使ってアクセスできる、キー/値ペアのコレクションを表します。
SortedList データ型で公開されるメンバを以下の表に示します。



名前 | 説明 | |
---|---|---|
![]() | Add | 指定したキーおよび値を持つ要素を SortedList に追加します。 |
![]() | Clear | SortedList からすべての要素を削除します。 |
![]() | Clone | SortedList の簡易コピーを作成します。 |
![]() | Contains | SortedList に特定のキーが格納されているかどうかを判断します。 |
![]() | ContainsKey | SortedList に特定のキーが格納されているかどうかを判断します。 |
![]() | ContainsValue | SortedList に特定の値が格納されているかどうかを判断します。 |
![]() | CopyTo | 1 次元の Array インスタンスの指定したインデックスに SortedList の要素をコピーします。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetByIndex | SortedList の指定したインデックスにある値を取得します。 |
![]() | GetEnumerator | SortedList を反復処理する IDictionaryEnumerator を返します。 |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetKey | SortedList の指定したインデックスにあるキーを取得します。 |
![]() | GetKeyList | SortedList 内のキーを取得します。 |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | GetValueList | SortedList 内の値を取得します。 |
![]() | IndexOfKey | SortedList 内の指定したキーの、0 から始まるインデックス番号を返します。 |
![]() | IndexOfValue | SortedList 内にある指定した値のうち、最初に出現する値の、0 から始まるインデックス番号を返します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | Remove | 指定したキーを持つ要素を SortedList から削除します。 |
![]() | RemoveAt | SortedList の指定したインデックスにある要素を削除します。 |
![]() | SetByIndex | SortedList の特定のインデックスにある値を置換します。 |
![]() | Synchronized | SortedList 用の同期された (スレッド セーフな) ラッパーを返します。 |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |
![]() | TrimToSize | 容量を SortedList 内にある実際の要素数に設定します。 |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |


- SortedListのページへのリンク