SortedListとは? わかりやすく解説

SortedList クラス

キーによって並べ替えられ、キーインデックス使ってアクセスできる、キー/値ペアコレクション表します

名前空間: System.Collections
アセンブリ: 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
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public class SortedList implements IDictionary,
 ICollection, 
    IEnumerable, ICloneable
SerializableAttribute 
ComVisibleAttribute(true) 
public class SortedList implements 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.Object
  System.Collections.SortedList
スレッド セーフスレッド セーフ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

SortedList コンストラクタ ()

空で、既定初期量を備え、SortedList に追加された各キーによって実装されている IComparable インターフェイスに従って並べ替えられた、SortedList クラス新しインスタンス初期化します。

名前空間: System.Collections
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

public SortedList ()
public:
SortedList ()
public SortedList ()
解説解説

キーは、SortedList 内の他のキーとの比較を行うことができるように、IComparable インターフェイス実装する必要があります要素は、SortedList追加された各キーIComparable 実装基づいて並べ替えられます。

SortedList容量は、SortedList保持できる要素数になりますSortedList要素追加すると、必要に応じて内部配列の再割り当てによって容量自動的に増加します。

コレクションサイズ推定できる場合は、初期量を指定すると、SortedList要素追加するときに、サイズ変更操作何度も実行する必要がなくなります

このコンストラクタは O(1) 操作です。

使用例使用例

異な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 : !

*/

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

SortedList コンストラクタ ()

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

空で、既定初期量を備え既定の IComparer を使用する、SortedList クラス新しインスタンス初期化します。

名前空間: System.Collections.Generic
アセンブリ: System (system.dll 内)
構文構文

Dim instance As New SortedList(Of
 TKey, TValue)
public SortedList ()
public:
SortedList ()
public SortedList ()
解説解説

SortedList 内のすべてのキー既定比較演算子に従って一意である必要があります

このコンストラクタは、SortedList初期量として既定値使用します初期量を設定するには、SortedList(Int32) コンストラクタ使用しますコレクション最終的なサイズ推定できる場合初期量を指定すると、SortedList要素追加するときにサイズ変更操作何度も実行する必要がなくなります

このコンストラクタは、TKey既定比較演算子使用します比較演算子指定するには、SortedList(ジェネリック IComparer) コンストラクタ使用します既定比較演算子 Comparer.Default は、キーの型 TKey が System.IComparable を実装し、利用可能場合その実装を使用するかどうかチェックしますそれ以外場合は、Comparer.Default によって、キーの型 TKey が System.IComparable を実装するかどうかチェックしますキーの型 TKeyいずれのインターフェイス実装ない場合は、comparer パラメータ受け取コンストラクタ オーバーロードSystem.Collections.Generic.IComparer 実装指定できます

このコンストラクタは O(1) 操作です。

使用例使用例

文字列キーを含む文字列の空の 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.");
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

SortedList コンストラクタ (IDictionary)

指定したディクショナリからコピーした要素格納しコピーした要素の数と同じ初期量を備え、各キーによって実装されている IComparable インターフェイスに従って並べ替えられた、SortedList クラス新しインスタンス初期化します。

名前空間: System.Collections
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    d As IDictionary _
)
Dim d As IDictionary

Dim instance As New SortedList(d)
public SortedList (
    IDictionary d
)
public:
SortedList (
    IDictionary^ d
)
public SortedList (
    IDictionary d
)
public function SortedList (
    d : IDictionary
)

パラメータ

d

新しい SortedList にコピーする IDictionary。

例外例外
例外種類条件

ArgumentNullException

dnull 参照 (Visual Basic では Nothing) です。

InvalidCastException

d1 つ上の要素が、IComparable インターフェイス実装していません。

解説解説

キーは、SortedList 内の他のキーとの比較を行うことができるように、IComparable インターフェイス実装する必要があります要素は、SortedList追加された各キーIComparable 実装基づいて並べ替えられます。

Hashtable は、このコンストラクタに渡すことができる IDictionary 実装一例です。新しSortedList には、Hashtable並べ替えられたキーと値のコピー格納されます。

SortedList容量は、SortedList保持できる要素数になりますSortedList要素追加すると、必要に応じて内部配列の再割り当てによって容量自動的に増加します。

コレクションサイズ推定できる場合は、初期量を指定すると、SortedList要素追加するときに、サイズ変更操作何度も実行する必要がなくなります

このコンストラクタは O(n) 操作です (nd 内の要素数)。

使用例使用例

異な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 : !

*/

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

SortedList コンストラクタ (Int32, ジェネリック IComparer)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

空で、指定した初期量を備え指定した IComparer使用するSortedList クラス新しインスタンス初期化します。

名前空間: System.Collections.Generic
アセンブリ: System (system.dll 内)
構文構文

Public Sub New ( _
    capacity As Integer, _
    comparer As IComparer(Of TKey) _
)
Dim capacity As Integer
Dim comparer As IComparer(Of
 TKey)

Dim instance As New SortedList(Of
 TKey, TValue)(capacity, comparer)
public SortedList (
    int capacity,
    IComparer<TKey> comparer
)
public:
SortedList (
    int capacity, 
    IComparer<TKey>^ comparer
)
public SortedList (
    int capacity, 
    IComparer<TKey> comparer
)
public function SortedList (
    capacity : int, 
    comparer : IComparer<TKey>
)

パラメータ

capacity

SortedList が格納できる要素数の初期値

comparer

キー比較する場合使用する IComparer 実装

または

キーの型に既定の Comparer を使用する場合null 参照 (Visual Basic では Nothing)。

例外例外
例外種類条件

ArgumentOutOfRangeException

capacity が 0 未満です。

解説解説
使用例使用例

初期量 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
 */
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

SortedList コンストラクタ

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 クラス
SortedList メンバ
System.Collections 名前空間
IComparable インターフェイス
Capacity

その他の技術情報

カルチャを認識しないコレクション操作実行

SortedList コンストラクタ (Int32)

空で、既定初期量を備えSortedList追加された各キーによって実装されている IComparable インターフェイスに従って並べ替えられた、SortedList クラス新しインスタンス初期化します。

名前空間: System.Collections
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    initialCapacity As Integer _
)
Dim initialCapacity As Integer

Dim instance As New SortedList(initialCapacity)
public SortedList (
    int initialCapacity
)
public:
SortedList (
    int initialCapacity
)
public SortedList (
    int initialCapacity
)
public function SortedList (
    initialCapacity : int
)

パラメータ

initialCapacity

SortedList が格納できる要素数の初期値

例外例外
例外種類条件

ArgumentOutOfRangeException

initialCapacity が 0 未満です。

OutOfMemoryException

メモリ不足しているため、指定されinitialCapacity を持つ SortedList作成できません。

解説解説

キーは、SortedList 内の他のキーとの比較を行うことができるように、IComparable インターフェイス実装する必要があります要素は、SortedList追加された各キーIComparable 実装基づいて並べ替えられます。

SortedList容量は、SortedList保持できる要素数になりますSortedList要素追加すると、必要に応じて内部配列の再割り当てによって容量自動的に増加します。

コレクションサイズ推定できる場合は、初期量を指定すると、SortedList要素追加するときに、サイズ変更操作何度も実行する必要がなくなります

このコンストラクタは O(n) 操作です (ninitialCapacity)。

使用例使用例

異な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 : !

*/

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

SortedList コンストラクタ (IComparer, Int32)

空で、指定した初期量を備え指定した IComparer インターフェイスに従って並べ替えられた、SortedList クラス新しインスタンス初期化します。

名前空間: System.Collections
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    comparer As IComparer, _
    capacity As Integer _
)
Dim comparer As IComparer
Dim capacity As Integer

Dim instance As New SortedList(comparer,
 capacity)
public SortedList (
    IComparer comparer,
    int capacity
)
public:
SortedList (
    IComparer^ comparer, 
    int capacity
)
public SortedList (
    IComparer comparer, 
    int capacity
)
public function SortedList (
    comparer : IComparer, 
    capacity : int
)

パラメータ

comparer

キー比較する場合使用する IComparer 実装

または

キーの IComparable 実装使用する場合null 参照 (Visual Basic では Nothing)。

capacity

SortedList が格納できる要素数の初期値

例外例外
例外種類条件

ArgumentOutOfRangeException

capacity が 0 未満です。

OutOfMemoryException

メモリ不足しているため、指定されcapacity を持つ SortedList作成できません。

解説解説

要素は、指定した IComparer 実装基づいて並べ替えられます。comparernull 参照 (Visual Basic では Nothing) の場合、各キーIComparable 実装使用されます。たがって、各キーは、SortedList 内の他のキーとの比較を行うことができるように、IComparable インターフェイス実装する必要があります

SortedList容量は、SortedList保持できる要素数になりますSortedList要素追加すると、必要に応じて内部配列の再割り当てによって容量自動的に増加します。

コレクションサイズ推定できる場合は、初期量を指定すると、SortedList要素追加するときに、サイズ変更操作何度も実行する必要がなくなります

このコンストラクタは O(n) 操作です (ncapacity)。

使用例使用例

異な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 : !

*/

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

SortedList コンストラクタ (IDictionary, IComparer)

指定したディクショナリからコピーした要素格納しコピーした要素の数と同じ初期量を備え指定した IComparer インターフェイスに従って並べ替えられた、SortedList クラス新しインスタンス初期化します。

名前空間: System.Collections
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    d As IDictionary, _
    comparer As IComparer _
)
Dim d As IDictionary
Dim comparer As IComparer

Dim instance As New SortedList(d,
 comparer)
public SortedList (
    IDictionary d,
    IComparer comparer
)
public:
SortedList (
    IDictionary^ d, 
    IComparer^ comparer
)
public SortedList (
    IDictionary d, 
    IComparer comparer
)
public function SortedList (
    d : IDictionary, 
    comparer : IComparer
)

パラメータ

d

新しい SortedList にコピーする IDictionary。

comparer

キー比較する場合使用する IComparer 実装

または

キーの IComparable 実装使用する場合null 参照 (Visual Basic では Nothing)。

例外例外
例外種類条件

ArgumentNullException

dnull 参照 (Visual Basic では Nothing) です。

InvalidCastException

comparernull 参照 (Visual Basic では Nothing) で、d1 つ上の要素IComparable インターフェイス実装していません。

解説解説

要素は、指定した IComparer 実装基づいて並べ替えられます。comparernull 参照 (Visual Basic では Nothing) の場合、各キーIComparable 実装使用されます。たがって、各キーは、SortedList 内の他のキーとの比較を行うことができるように、IComparable インターフェイス実装する必要があります

Hashtable は、このコンストラクタに渡すことができる IDictionary 実装一例です。新しSortedList には、Hashtable並べ替えられたキーと値のコピー格納されます。

SortedList容量は、SortedList保持できる要素数になりますSortedList要素追加すると、必要に応じて内部配列の再割り当てによって容量自動的に増加します。

コレクションサイズ推定できる場合は、初期量を指定すると、SortedList要素追加するときに、サイズ変更操作何度も実行する必要がなくなります

このコンストラクタは O(n) 操作です (nd 内の要素数)。

使用例使用例

異な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 : !

*/

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

SortedList コンストラクタ (IComparer)

空で、既定初期量を備え指定した IComparer インターフェイスに従って並べ替えられた、SortedList クラス新しインスタンス初期化します。

名前空間: System.Collections
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    comparer As IComparer _
)
Dim comparer As IComparer

Dim instance As New SortedList(comparer)
public SortedList (
    IComparer comparer
)
public:
SortedList (
    IComparer^ comparer
)
public SortedList (
    IComparer comparer
)
public function SortedList (
    comparer : IComparer
)

パラメータ

comparer

キー比較する場合使用する IComparer 実装

または

キーの IComparable 実装使用する場合null 参照 (Visual Basic では Nothing)。

解説解説

要素は、指定した IComparer 実装基づいて並べ替えられます。comparernull 参照 (Visual Basic では Nothing) の場合、各キーIComparable 実装使用されます。たがって、各キーは、SortedList 内の他のキーとの比較を行うことができるように、IComparable インターフェイス実装する必要があります

SortedList容量は、SortedList保持できる要素数になりますSortedList要素追加すると、必要に応じて内部配列の再割り当てによって容量自動的に増加します。

コレクションサイズ推定できる場合は、初期量を指定すると、SortedList要素追加するときに、サイズ変更操作何度も実行する必要がなくなります

このコンストラクタは O(1) 操作です。

使用例使用例

異な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 : !

*/

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

SortedList コンストラクタ

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)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

空で、既定初期量を備え指定した IComparer使用する、SortedList クラス新しインスタンス初期化します。

名前空間: System.Collections.Generic
アセンブリ: System (system.dll 内)
構文構文

Public Sub New ( _
    comparer As IComparer(Of TKey) _
)
Dim comparer As IComparer(Of
 TKey)

Dim instance As New SortedList(Of
 TKey, TValue)(comparer)
public SortedList (
    IComparer<TKey> comparer
)
public:
SortedList (
    IComparer<TKey>^ comparer
)
public SortedList (
    IComparer<TKey> comparer
)
public function SortedList (
    comparer : IComparer<TKey>
)

パラメータ

comparer

キー比較する場合使用する IComparer 実装

または

キーの型に既定の Comparer を使用する場合null 参照 (Visual Basic では Nothing)。

解説解説
使用例使用例

現在のカルチャの大文字小文字区別しない比較演算子使って並べ替えられたリスト作成するコード例次に示します。この例では、小文字キーを含む要素大文字キーを含む要素合わせて 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
 */
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

SortedList コンストラクタ (ジェネリック IDictionary)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

指定した IDictionary からコピーした要素格納しコピーした要素の数を格納できるだけの容量備え既定の IComparer を使用するSortedList クラス新しインスタンス初期化します。

名前空間: System.Collections.Generic
アセンブリ: 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>
)

パラメータ

dictionary

新しい SortedList に要素コピーされた IDictionary。

例外例外
例外種類条件

ArgumentNullException

dictionarynull 参照 (Visual Basic では Nothing) です。

ArgumentException

dictionary に、1 つ上の重複するキー格納されています。

解説解説

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) 操作です (ndictionary 内の要素数)。そうでない場合は O(n*n) 操作です。

使用例使用例

DictionarySortedList(ジェネリック 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
 */
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

SortedList コンストラクタ (Int32)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

空で、指定した初期量を備え既定の IComparer を使用するSortedList クラス新しインスタンス初期化します。

名前空間: System.Collections.Generic
アセンブリ: System (system.dll 内)
構文構文

例外例外
例外種類条件

ArgumentOutOfRangeException

capacity が 0 未満です。

解説解説

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 実装指定できます

このコンストラクタは O(n) 操作です (ncapacity)。

使用例使用例

並べ替えられたリスト初期量 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
 */
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

SortedList コンストラクタ (ジェネリック IDictionary, ジェネリック IComparer)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

指定した IDictionary からコピーした要素格納しコピーした要素の数を格納できるだけの容量備え指定した IComparer使用するSortedList クラス新しインスタンス初期化します。

名前空間: System.Collections.Generic
アセンブリ: 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>
)

パラメータ

dictionary

新しい SortedList に要素コピーされた IDictionary。

comparer

キー比較する場合使用する IComparer 実装

または

キーの型に既定の Comparer を使用する場合null 参照 (Visual Basic では Nothing)。

例外例外
例外種類条件

ArgumentNullException

dictionarynull 参照 (Visual Basic では Nothing) です。

ArgumentException

dictionary に、1 つ上の重複するキー格納されています。

解説解説
使用例使用例

DictionarySortedList(ジェネリック 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
 */
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

SortedList ジェネリック クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

関連付けられた IComparer 実装基づいてキー並べ替えられた、キー/値ペアコレクション表します

名前空間: System.Collections.Generic
アセンブリ: 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
Dim instance As SortedList(Of
 TKey, TValue)
[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
J# では、ジェネリックな型およびメソッド使用できますが、新規に宣言することはできません。
JScript では、ジェネリックな型およびメソッド使用できません。

型パラメータ

TKey

コレクション内のキーの型。

TValue

コレクション内の値の型。

解説解説

SortedList ジェネリック クラスは、O(log n) 取得使用するバイナリ サーチ ツリーです。n は、ディクショナリ内の要素数を示します。この点で、これは SortedDictionary ジェネリック クラス似てます。この 2 つクラスには、同じようオブジェクト モデルがあり、どちらも O(log n) 取得備えてます。この 2 つクラス違いは、メモリ使用方法と、挿入および削除速度です。

SortedDictionary クラスSortedList クラス違いとして、SortedListキーと値の効率的なインデックスによる取得サポートしていることも挙げられます。これには、Keys プロパティおよび Values プロパティによって返されるコレクション使用されます。リストキーと値の内部配列単なるラッパーなので、プロパティへのアクセス時にリスト再生成する必要はありません。Values プロパティ使用して文字列並べ替えられたリストの値をインデックス取得するコード例次に示します

Dim v As String = mySortedList.Values(3)
string v = mySortedList.Values[3];
String^ v = mySortedList->Values[3];

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 eachVisual Basic の場合For Each) には、コレクション内の要素の型が必要です。SortedList要素キー/値ペアであるため、要素の型は、キーの型や値の型にはなりません。その代わり要素の型は KeyValuePairなります次に例を示します

foreach (KeyValuePair<int, string>
 kvp in mySortedList) {...}
for each (KeyValuePair<int, String^>
 kvp in mySortedList) {...}
For Each kvp As KeyValuePair(Of
 Integer, String) In mySortedList
    ...
Next kvp

foreach ステートメントは、列挙子のラッパーです。これは、コレクションからの読み取りだけを許可しコレクションへの書き込み防ぎます

使用例使用例

文字列キーを含む文字列の空の SortedList作成しAdd メソッド使用していくつかの要素追加するコード例次に示します。この例では、重複するキー追加しようとすると、Add メソッドが ArgumentException をスローすることを示します

この例では、Item プロパティ (C# ではインデクサ) を使用して値を取得し要求されキー存在しないときに KeyNotFoundException がスローされる例を示し、またキー関連付けられた値を置き換えることができること示します

この例では、プログラム並べ替えられたリストにないキー値を頻繁に試行する必要がある場合に、より効率的に値を取得する方法として TryGetValue メソッド使用する方法、および Add メソッド呼び出す前にキー存在するかどうかテストするために ContainsKey メソッド使用する方法示します

この例では、並べ替えられたリストキーと値を列挙する方法、および Keys プロパティValues プロパティ使用してキーと値のみを列挙する方法示します

最後にRemove メソッド使用例示します

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.Object
  System.Collections.Generic.SortedList
スレッド セーフスレッド セーフ

この型の public static (Visual Basic では Shared) メンバは、スレッド セーフです。すべてのインスタンス メンバスレッド セーフになるかどうか保証されていません。

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

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

SortedList プロパティ


SortedList プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ Values SortedList 内の値を取得します
参照参照

関連項目

SortedList クラス
System.Collections 名前空間
IComparable インターフェイス
IComparer インターフェイス
IDictionary インターフェイス
Hashtable クラス
System.Collections.Generic.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 指定したキー関連付けられている値を取得します
プロテクト メソッドプロテクト メソッド
明示的インターフェイスの実装明示的インターフェイス実装
  名前 説明
インターフェイスの明示的な実装 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 メソッド


パブリック メソッドパブリック メソッド

( プロテクト メソッド参照)
  名前 説明
パブリック メソッド 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 内にある実際要素数に設定します
プロテクト メソッドプロテクト メソッド
明示的インターフェイスの実装明示的インターフェイス実装
  名前 説明
インターフェイスの明示的な実装 System.Collections.IEnumerable.GetEnumerator SortedList反復処理する IEnumerator を返します
参照参照

関連項目

SortedList クラス
System.Collections 名前空間
IComparable インターフェイス
IComparer インターフェイス
IDictionary インターフェイス
Hashtable クラス
System.Collections.Generic.SortedList

その他の技術情報

カルチャを認識しないコレクション操作実行

SortedList メンバ

関連付けられた IComparer 実装基づいてキー並べ替えられた、キー/値ペアコレクション表します

SortedList ジェネリック型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ Values 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 指定したキー関連付けられている値を取得します
プロテクト メソッドプロテクト メソッド
明示的インターフェイスの実装明示的インターフェイス実装
  名前 説明
インターフェイスの明示的な実装 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 メンバ

キーによって並べ替えられ、キーインデックス使ってアクセスできる、キー/値ペアコレクション表します

SortedList データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ Values 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 内にある実際要素数に設定します
プロテクト メソッドプロテクト メソッド
明示的インターフェイスの実装明示的インターフェイス実装
  名前 説明
インターフェイスの明示的な実装 System.Collections.IEnumerable.GetEnumerator SortedList反復処理する IEnumerator を返します
参照参照

関連項目

SortedList クラス
System.Collections 名前空間
IComparable インターフェイス
IComparer インターフェイス
IDictionary インターフェイス
Hashtable クラス
System.Collections.Generic.SortedList

その他の技術情報

カルチャを認識しないコレクション操作実行



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「SortedList」の関連用語

SortedListのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



SortedListのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS