SortedList<TKey,TValue> クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
関連付けられた IComparer<T> 実装に基づいて、キーにより並べ替えられた、キーと値のペアのコレクションを表します。
generic <typename TKey, typename TValue>
public ref class SortedList : System::Collections::Generic::ICollection<System::Collections::Generic::KeyValuePair<TKey, TValue>>, System::Collections::Generic::IDictionary<TKey, TValue>, System::Collections::Generic::IEnumerable<System::Collections::Generic::KeyValuePair<TKey, TValue>>, System::Collections::Generic::IReadOnlyCollection<System::Collections::Generic::KeyValuePair<TKey, TValue>>, System::Collections::Generic::IReadOnlyDictionary<TKey, TValue>, System::Collections::IDictionary
generic <typename TKey, typename TValue>
public ref class SortedList : System::Collections::Generic::ICollection<System::Collections::Generic::KeyValuePair<TKey, TValue>>, System::Collections::Generic::IDictionary<TKey, TValue>, System::Collections::Generic::IEnumerable<System::Collections::Generic::KeyValuePair<TKey, TValue>>, System::Collections::IDictionary
public class SortedList<TKey,TValue> : System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>, System.Collections.Generic.IDictionary<TKey,TValue>, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey,TValue>>, System.Collections.Generic.IReadOnlyCollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>, System.Collections.Generic.IReadOnlyDictionary<TKey,TValue>, System.Collections.IDictionary
[System.Runtime.InteropServices.ComVisible(false)]
[System.Serializable]
public class SortedList<TKey,TValue> : System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>, System.Collections.Generic.IDictionary<TKey,TValue>, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey,TValue>>, System.Collections.IDictionary
[System.Runtime.InteropServices.ComVisible(false)]
[System.Serializable]
public class SortedList<TKey,TValue> : System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>, System.Collections.Generic.IDictionary<TKey,TValue>, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey,TValue>>, System.Collections.Generic.IReadOnlyCollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>, System.Collections.Generic.IReadOnlyDictionary<TKey,TValue>, System.Collections.IDictionary
type SortedList<'Key, 'Value> = class
interface ICollection<KeyValuePair<'Key, 'Value>>
interface seq<KeyValuePair<'Key, 'Value>>
interface IEnumerable
interface IDictionary<'Key, 'Value>
interface IReadOnlyCollection<KeyValuePair<'Key, 'Value>>
interface IReadOnlyDictionary<'Key, 'Value>
interface ICollection
interface IDictionary
[<System.Runtime.InteropServices.ComVisible(false)>]
[<System.Serializable>]
type SortedList<'Key, 'Value> = class
interface IDictionary<'Key, 'Value>
interface ICollection<KeyValuePair<'Key, 'Value>>
interface seq<KeyValuePair<'Key, 'Value>>
interface IDictionary
interface ICollection
interface IEnumerable
[<System.Runtime.InteropServices.ComVisible(false)>]
[<System.Serializable>]
type SortedList<'Key, 'Value> = class
interface IDictionary<'Key, 'Value>
interface ICollection<KeyValuePair<'Key, 'Value>>
interface seq<KeyValuePair<'Key, 'Value>>
interface IEnumerable
interface IDictionary
interface ICollection
interface IReadOnlyDictionary<'Key, 'Value>
interface IReadOnlyCollection<KeyValuePair<'Key, 'Value>>
[<System.Runtime.InteropServices.ComVisible(false)>]
[<System.Serializable>]
type SortedList<'Key, 'Value> = class
interface IDictionary<'Key, 'Value>
interface IDictionary
interface IReadOnlyDictionary<'Key, 'Value>
interface ICollection<KeyValuePair<'Key, 'Value>>
interface seq<KeyValuePair<'Key, 'Value>>
interface IEnumerable
interface ICollection
interface IReadOnlyCollection<KeyValuePair<'Key, 'Value>>
Public Class SortedList(Of TKey, TValue)
Implements ICollection(Of KeyValuePair(Of TKey, TValue)), IDictionary, IDictionary(Of TKey, TValue), IEnumerable(Of KeyValuePair(Of TKey, TValue)), IReadOnlyCollection(Of KeyValuePair(Of TKey, TValue)), IReadOnlyDictionary(Of TKey, TValue)
Public Class SortedList(Of TKey, TValue)
Implements ICollection(Of KeyValuePair(Of TKey, TValue)), IDictionary, IDictionary(Of TKey, TValue), IEnumerable(Of KeyValuePair(Of TKey, TValue))
型パラメーター
- TKey
コレクション内のキーの型。
- TValue
コレクション内の値の型。
- 継承
-
SortedList<TKey,TValue>
- 派生
- 属性
- 実装
-
ICollection<KeyValuePair<TKey,TValue>> IDictionary<TKey,TValue> IEnumerable<KeyValuePair<TKey,TValue>> IEnumerable<T> IReadOnlyCollection<KeyValuePair<TKey,TValue>> IReadOnlyDictionary<TKey,TValue> ICollection IDictionary IEnumerable
例
次のコード例では、文字列キーを SortedList<TKey,TValue> 含む空の文字列を作成し、 メソッドを Add 使用していくつかの要素を追加します。 この例では、重複するキーを Add 追加しようとしたときに メソッドが を ArgumentException スローすることを示します。
この例では、 Item[] プロパティ (C#のインデクサー) を使用して値を取得し、要求されたキーが存在しない場合に がスローされることを示 KeyNotFoundException し、キーに関連付けられている値を置き換えることができることを示しています。
例を使用する方法を示します、TryGetValueメソッド値を取得する場合は、プログラムは多くの場合、並べ替えられたリストに含まれていないキーの値を試行する必要があり、使用する方法を示しますより効率的な方法として、 ContainsKey を呼び出す前に、キーが存在するかどうかをテストする方法をAddメソッドです。
この例では、並べ替えられたリスト内のキーと値を列挙する方法と、 プロパティと プロパティを使用して Keys キーと値だけを列挙する方法を Values 示します。
最後に、 メソッドの例を Remove 示します。
#using <System.dll>
using namespace System;
using namespace System::Collections::Generic;
public ref class Example
{
public:
static void Main()
{
// Create a new sorted list of strings, with string
// keys.
SortedList<String^, String^>^ openWith =
gcnew 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", 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();
for each( 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 SortedList values.
Console::WriteLine();
for each( 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();
for each( 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.");
}
}
};
int main()
{
Example::Main();
}
/* 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 SortedList 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.
*/
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.
'
注釈
SortedList<TKey,TValue>ジェネリック クラスは、O(log n
) 取得を含むキーと値のペアの配列です。n はディクショナリ内の要素の数です。 このでは、ジェネリック クラスに SortedDictionary<TKey,TValue> 似ています。 2 つのクラスには同様のオブジェクト モデルがあり、どちらも O(log n
) 取得があります。 2 つのクラスが異なるのは、メモリ使用量と挿入と削除の速度です。
SortedList<TKey,TValue> より少ないメモリを SortedDictionary<TKey,TValue>使用します。
SortedDictionary<TKey,TValue>には、 の O() ではなく、並べ替えられていないデータ (O(log
n
) SortedList<TKey,TValue>に対するn
挿入と削除の操作が高速です。並べ替えられたデータからリストがすべて一度に設定される場合は、 SortedList<TKey,TValue> よりも SortedDictionary<TKey,TValue>高速です。
クラスと SortedList<TKey,TValue> クラスのSortedDictionary<TKey,TValue>もう 1 つの違いは、 SortedList<TKey,TValue> プロパティと Values プロパティによって返されるコレクションを使用して、キーと値の効率的なインデックス取得をKeysサポートすることです。 リストはキーと値の内部配列のラッパーに過ぎないため、プロパティにアクセスするときにリストを再生成する必要はありません。 次のコードは、並べ替えられた文字列の Values 一覧から値をインデックス取得するために プロパティを使用する方法を示しています。
String^ v = mySortedList->Values[3];
string v = mySortedList.Values[3];
Dim v As String = mySortedList.Values(3)
SortedList<TKey,TValue> は、キーと値のペアの配列として実装され、キーで並べ替えられます。 各要素は、オブジェクトとして KeyValuePair<TKey,TValue> 取得できます。
キー オブジェクトは、 で SortedList<TKey,TValue>キーとして使用されている限り、不変である必要があります。 内のすべてのキーは SortedList<TKey,TValue> 一意である必要があります。 キーを に null
することはできませんが、リスト内の値の型が参照型である場合は、 TValue
値を にすることができます。
SortedList<TKey,TValue> には、並べ替えと比較を実行するための比較子の実装が必要です。 既定の比較子 Comparer<T>.Default は、キー型 TKey
がその実装を実装 System.IComparable<T> し、使用可能な場合はその実装を使用するかどうかを確認します。 そうでない場合は、 Comparer<T>.Default キー型 TKey
が を実装しているかどうかを確認します System.IComparable。 キー型 TKey
がどちらのインターフェイスも実装していない場合は、パラメーターを System.Collections.Generic.IComparer<T> 受け取るコンストラクター オーバーロードで実装を comparer
指定できます。
SortedList<TKey,TValue>の容量は、SortedList<TKey,TValue>が保持できる要素の数です。 要素が に SortedList<TKey,TValue>追加されると、内部配列を再割り当てすることで、必要に応じて容量が自動的に増加します。 を呼び出 TrimExcess すか、 プロパティを明示的に設定することで、容量を Capacity 減らすことができます。 容量を減らすと、メモリが再割り当てされ、 内のすべての要素がコピーされます SortedList<TKey,TValue>。
.NET Frameworkのみ: 非常に大きなSortedList<TKey,TValue>オブジェクトの場合は、実行時環境で 構成要素の <gcAllowVeryLargeObjects>
属性を に設定enabled
することで、64 ビット システムで最大容量を true
20 億要素に増やすことができます。
C# 言語for each
(Visual Basic では C++ の場合) の ステートメントはforeach
、For Each
コレクション内の要素の型のオブジェクトを返します。 の要素はキーと値の SortedList<TKey,TValue> ペアであるため、要素の型はキーの型や値の型ではありません。 代わりに、要素の型は です KeyValuePair<TKey,TValue>。 次に例を示します。
for each( KeyValuePair<int, String^> kvp in mySortedList )
{
Console::WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
}
foreach( KeyValuePair<int, string> kvp in mySortedList )
{
Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
}
For Each kvp As KeyValuePair(Of Integer, String) In mySortedList
Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value)
Next kvp
ステートメントは foreach
列挙子のラッパーであり、コレクションからの読み取りのみが許可され、コレクションへの書き込みは許可されません。
コンストラクター
SortedList<TKey,TValue>() |
空で、既定の初期量を備え、既定の SortedList<TKey,TValue> を使用する、IComparer<T> クラスの新しいインスタンスを初期化します。 |
SortedList<TKey,TValue>(IComparer<TKey>) |
空で、既定の初期量を備え、指定した SortedList<TKey,TValue> を使用する、IComparer<T> クラスの新しいインスタンスを初期化します。 |
SortedList<TKey,TValue>(IDictionary<TKey,TValue>) |
指定した SortedList<TKey,TValue> からコピーした要素を格納し、コピーした要素の数を格納できるだけの容量を備え、既定の IDictionary<TKey,TValue> を使用する、IComparer<T> クラスの新しいインスタンスを初期化します。 |
SortedList<TKey,TValue>(IDictionary<TKey,TValue>, IComparer<TKey>) |
指定した SortedList<TKey,TValue> からコピーした要素を格納し、コピーした要素の数を格納できるだけの容量を備え、指定した IDictionary<TKey,TValue> を使用する、IComparer<T> クラスの新しいインスタンスを初期化します。 |
SortedList<TKey,TValue>(Int32) |
空で、指定した初期量を備え、既定の SortedList<TKey,TValue> を使用する、IComparer<T> クラスの新しいインスタンスを初期化します。 |
SortedList<TKey,TValue>(Int32, IComparer<TKey>) |
空で、指定した初期量を備え、指定した SortedList<TKey,TValue> を使用する、IComparer<T> クラスの新しいインスタンスを初期化します。 |
プロパティ
Capacity |
SortedList<TKey,TValue> に格納できる要素の数を取得または設定します。 |
Comparer |
並べ替えられたリストの IComparer<T> を取得します。 |
Count |
SortedList<TKey,TValue> に格納されているキー/値ペアの数を取得します。 |
Item[TKey] |
指定されたキーに関連付けられている値を取得または設定します。 |
Keys |
並べ替えられた順序で、SortedList<TKey,TValue> 内のキーを含むコレクションを取得します。 |
Values |
SortedList<TKey,TValue> 内の値を格納しているコレクションを取得します。 |
メソッド
明示的なインターフェイスの実装
拡張メソッド
適用対象
スレッド セーフ
パブリック静的 (Visual Basic ではShared
) なこの型のメンバーはスレッド セーフです インスタンス メンバーの場合は、スレッド セーフであるとは限りません。
SortedList<TKey,TValue>コレクションが変更されていない限り、 は複数のリーダーを同時にサポートできます。 それでも、コレクションを列挙することは、本質的にスレッド セーフなプロシージャではありません。 列挙処理でスレッド セーフを確保するには、列挙処理が終わるまでコレクションをロックできます。 コレクションに対し複数のスレッドがアクセスして読み取りや書き込みを行うことができるようにするには、独自に同期化を実装する必要があります。