SortedList<TKey,TValue> SortedList<TKey,TValue> SortedList<TKey,TValue> SortedList<TKey,TValue> Class

Définition

Représente une collection de paires clé/valeur triées par clé en fonction de l'implémentation IComparer<T> associée.Represents a collection of key/value pairs that are sorted by key based on the associated IComparer<T> implementation.

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
[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 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)

Paramètres de type

TKey

Type de clés de la collection.The type of keys in the collection.

TValue

Type de valeurs de la collection.The type of values in the collection.

Héritage
SortedList<TKey,TValue>SortedList<TKey,TValue>SortedList<TKey,TValue>SortedList<TKey,TValue>
Dérivé
Attributs
Implémente

Exemples

L’exemple de code suivant crée un SortedList<TKey,TValue> vide de chaînes avec des clés de chaîne Add et utilise la méthode pour ajouter des éléments.The following code example creates an empty SortedList<TKey,TValue> of strings with string keys and uses the Add method to add some elements. L’exemple montre que la Add méthode lève une ArgumentException exception lors de la tentative d’ajout d’une clé dupliquée.The example demonstrates that the Add method throws an ArgumentException when attempting to add a duplicate key.

L’exemple utilise la Item[TKey] propriété (l’indexeur dans C#) pour récupérer des valeurs, en montrant qu' KeyNotFoundException une exception est levée lorsqu’une clé demandée n’est pas présente, et montrant que la valeur associée à une clé peut être remplacée.The example uses the Item[TKey] property (the indexer in C#) to retrieve values, demonstrating that a KeyNotFoundException is thrown when a requested key is not present, and showing that the value associated with a key can be replaced.

L’exemple montre comment utiliser le TryGetValue méthode comme un moyen plus efficace pour récupérer des valeurs si un programme doit souvent essayer des valeurs de clés qui ne sont pas dans la liste triée, et il montre comment utiliser la ContainsKey méthode pour tester si une clé existe avant d’appeler le Add (méthode).The example shows how to use the TryGetValue method as a more efficient way to retrieve values if a program often must try key values that are not in the sorted list, and it shows how to use the ContainsKey method to test whether a key exists before calling the Add method.

L’exemple montre comment énumérer les clés et les valeurs de la liste triée et comment énumérer les clés et les valeurs uniquement à Keys l’aide de Values la propriété et de la propriété.The example shows how to enumerate the keys and values in the sorted list and how to enumerate the keys and values alone using the Keys property and the Values property.

Enfin, l’exemple illustre la Remove méthode.Finally, the example demonstrates the Remove method.

#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 SorteList 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 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.
 */
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.
' 

Remarques

La SortedList<TKey,TValue> classe générique est un tableau de paires clé/valeur avec une extraction O n(log), où n est le nombre d’éléments dans le dictionnaire.The SortedList<TKey,TValue> generic class is an array of key/value pairs with O(log n) retrieval, where n is the number of elements in the dictionary. Dans ce type, il est similaire à SortedDictionary<TKey,TValue> la classe générique.In this, it is similar to the SortedDictionary<TKey,TValue> generic class. Les deux classes ont des modèles objet similaires et ont toutes les deux la nrécupération O (log).The two classes have similar object models, and both have O(log n) retrieval. Les différences entre les deux classes sont l’utilisation de la mémoire et la vitesse d’insertion et de suppression:Where the two classes differ is in memory use and speed of insertion and removal:

Une autre différence entre SortedDictionary<TKey,TValue> les SortedList<TKey,TValue> classes et est SortedList<TKey,TValue> que prend en charge une récupération indexée efficace des clés et des valeurs via les Keys collections Values retournées par les propriétés et.Another difference between the SortedDictionary<TKey,TValue> and SortedList<TKey,TValue> classes is that SortedList<TKey,TValue> supports efficient indexed retrieval of keys and values through the collections returned by the Keys and Values properties. Il n’est pas nécessaire de régénérer les listes lors de l’accès aux propriétés, car les listes sont simplement des wrappers pour les tableaux internes de clés et de valeurs.It is not necessary to regenerate the lists when the properties are accessed, because the lists are just wrappers for the internal arrays of keys and values. Le code suivant illustre l’utilisation de la Values propriété pour la récupération indexée de valeurs à partir d’une liste triée de chaînes:The following code shows the use of the Values property for indexed retrieval of values from a sorted list of strings:

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

SortedList<TKey,TValue>est implémenté sous la forme d’un tableau de paires clé/valeur, trié par la clé.SortedList<TKey,TValue> is implemented as an array of key/value pairs, sorted by the key. Chaque élément peut être récupéré sous la KeyValuePair<TKey,TValue> forme d’un objet.Each element can be retrieved as a KeyValuePair<TKey,TValue> object.

Les objets clés doivent être immuables tant qu’ils sont utilisés en tant que clés SortedList<TKey,TValue>dans le.Key objects must be immutable as long as they are used as keys in the SortedList<TKey,TValue>. Chaque clé dans un SortedList<TKey,TValue> doit être unique.Every key in a SortedList<TKey,TValue> must be unique. Une clé ne peut nullpas être, mais une valeur peut être, si le type de valeurs de la TValueliste,, est un type référence.A key cannot be null, but a value can be, if the type of values in the list, TValue, is a reference type.

SortedList<TKey,TValue>requiert une implémentation de comparateur pour trier et effectuer des comparaisons.SortedList<TKey,TValue> requires a comparer implementation to sort and to perform comparisons. Le comparateur Comparer<T>.Default par défaut vérifie si le TKey type de System.IComparable<T> clé implémente et utilise cette implémentation, si elle est disponible.The default comparer Comparer<T>.Default checks whether the key type TKey implements System.IComparable<T> and uses that implementation, if available. Si ce n' Comparer<T>.Default est pas le cas, TKey vérifie si System.IComparablele type de clé implémente.If not, Comparer<T>.Default checks whether the key type TKey implements System.IComparable. Si le type TKey de clé n’implémente aucune interface, vous pouvez spécifier System.Collections.Generic.IComparer<T> une implémentation dans une surcharge de constructeur qui comparer accepte un paramètre.If the key type TKey does not implement either interface, you can specify a System.Collections.Generic.IComparer<T> implementation in a constructor overload that accepts a comparer parameter.

La capacité d’un SortedList<TKey,TValue> est le nombre d’éléments que SortedList<TKey,TValue> peut contenir.The capacity of a SortedList<TKey,TValue> is the number of elements the SortedList<TKey,TValue> can hold. À mesure que des éléments sont SortedList<TKey,TValue>ajoutés à un, la capacité est automatiquement augmentée en fonction des besoins en réallouant le tableau interne.As elements are added to a SortedList<TKey,TValue>, the capacity is automatically increased as required by reallocating the internal array. La capacité peut être réduite en appelant TrimExcess ou en définissant Capacity la propriété explicitement.The capacity can be decreased by calling TrimExcess or by setting the Capacity property explicitly. La réduction de la capacité réalloue la mémoire et copie tous les éléments SortedList<TKey,TValue>dans.Decreasing the capacity reallocates memory and copies all the elements in the SortedList<TKey,TValue>.

.NET Framework uniquement: Pour les objets SortedList<TKey,TValue> très volumineux, vous pouvez augmenter la capacité maximale à 2 milliards éléments sur un système 64 bits en affectant enabled à true l’attribut <gcAllowVeryLargeObjects> de l’élément de configuration la valeur dans l’environnement d’exécution..NET Framework only: For very large SortedList<TKey,TValue> objects, you can increase the maximum capacity to 2 billion elements on a 64-bit system by setting the enabled attribute of the <gcAllowVeryLargeObjects> configuration element to true in the run-time environment.

L' foreach instruction de la C# for eachlangue( dans C++retourne un objet du type des éléments dans la collection. For EachThe foreach statement of the C# language (for each in C++, For Each in Visual Basic) returns an object of the type of the elements in the collection. Étant donné que les éléments SortedList<TKey,TValue> de sont des paires clé/valeur, le type d’élément n’est pas le type de la clé ou le type de la valeur.Since the elements of the SortedList<TKey,TValue> are key/value pairs, the element type is not the type of the key or the type of the value. Au lieu de cela, le KeyValuePair<TKey,TValue>type d’élément est.Instead, the element type is KeyValuePair<TKey,TValue>. Par exemple :For example:

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

L' foreach instruction est un wrapper autour de l’énumérateur, qui autorise uniquement la lecture, et non l’écriture, de la collection.The foreach statement is a wrapper around the enumerator, which only allows reading from, not writing to, the collection.

Constructeurs

SortedList<TKey,TValue>() SortedList<TKey,TValue>() SortedList<TKey,TValue>() SortedList<TKey,TValue>()

Initialise une nouvelle instance de la classe SortedList<TKey,TValue> qui est vide, possède la capacité initiale par défaut et utilise le IComparer<T> par défaut.Initializes a new instance of the SortedList<TKey,TValue> class that is empty, has the default initial capacity, and uses the default IComparer<T>.

SortedList<TKey,TValue>(IComparer<TKey>) SortedList<TKey,TValue>(IComparer<TKey>) SortedList<TKey,TValue>(IComparer<TKey>) SortedList<TKey,TValue>(IComparer<TKey>)

Initialise une nouvelle instance de la classe SortedList<TKey,TValue> qui est vide, possède la capacité initiale par défaut et utilise le IComparer<T> spécifié.Initializes a new instance of the SortedList<TKey,TValue> class that is empty, has the default initial capacity, and uses the specified IComparer<T>.

SortedList<TKey,TValue>(IDictionary<TKey,TValue>) SortedList<TKey,TValue>(IDictionary<TKey,TValue>) SortedList<TKey,TValue>(IDictionary<TKey,TValue>) SortedList<TKey,TValue>(IDictionary<TKey,TValue>)

Initialise une nouvelle instance de la classe SortedList<TKey,TValue> qui contient des éléments copiés à partir du IDictionary<TKey,TValue> spécifié, possède une capacité suffisante pour accepter le nombre d'éléments copiés et utilise le IComparer<T> par défaut.Initializes a new instance of the SortedList<TKey,TValue> class that contains elements copied from the specified IDictionary<TKey,TValue>, has sufficient capacity to accommodate the number of elements copied, and uses the default IComparer<T>.

SortedList<TKey,TValue>(IDictionary<TKey,TValue>, IComparer<TKey>) SortedList<TKey,TValue>(IDictionary<TKey,TValue>, IComparer<TKey>) SortedList<TKey,TValue>(IDictionary<TKey,TValue>, IComparer<TKey>) SortedList<TKey,TValue>(IDictionary<TKey,TValue>, IComparer<TKey>)

Initialise une nouvelle instance de la classe SortedList<TKey,TValue> qui contient des éléments copiés à partir du IDictionary<TKey,TValue> spécifié, possède une capacité suffisante pour accepter le nombre d'éléments copiés et utilise le IComparer<T> spécifié.Initializes a new instance of the SortedList<TKey,TValue> class that contains elements copied from the specified IDictionary<TKey,TValue>, has sufficient capacity to accommodate the number of elements copied, and uses the specified IComparer<T>.

SortedList<TKey,TValue>(Int32) SortedList<TKey,TValue>(Int32) SortedList<TKey,TValue>(Int32) SortedList<TKey,TValue>(Int32)

Initialise une nouvelle instance de la classe SortedList<TKey,TValue> qui est vide, possède la capacité initiale spécifiée et utilise le IComparer<T> par défaut.Initializes a new instance of the SortedList<TKey,TValue> class that is empty, has the specified initial capacity, and uses the default IComparer<T>.

SortedList<TKey,TValue>(Int32, IComparer<TKey>) SortedList<TKey,TValue>(Int32, IComparer<TKey>) SortedList<TKey,TValue>(Int32, IComparer<TKey>) SortedList<TKey,TValue>(Int32, IComparer<TKey>)

Initialise une nouvelle instance de la classe SortedList<TKey,TValue> qui est vide, possède la capacité initiale spécifiée et utilise le IComparer<T> spécifié.Initializes a new instance of the SortedList<TKey,TValue> class that is empty, has the specified initial capacity, and uses the specified IComparer<T>.

Propriétés

Capacity Capacity Capacity Capacity

Obtient ou définit le nombre d'éléments que SortedList<TKey,TValue> peut contenir.Gets or sets the number of elements that the SortedList<TKey,TValue> can contain.

Comparer Comparer Comparer Comparer

Obtient IComparer<T> pour la liste triée.Gets the IComparer<T> for the sorted list.

Count Count Count Count

Obtient le nombre de paires clé/valeur contenues dans SortedList<TKey,TValue>.Gets the number of key/value pairs contained in the SortedList<TKey,TValue>.

Item[TKey] Item[TKey] Item[TKey] Item[TKey]

Obtient ou définit la valeur associée à la clé spécifiée.Gets or sets the value associated with the specified key.

Keys Keys Keys Keys

Obtient une collection contenant les clés de la SortedList<TKey,TValue>, dans un ordre trié.Gets a collection containing the keys in the SortedList<TKey,TValue>, in sorted order.

Values Values Values Values

Obtient une collection contenant les valeurs de SortedList<TKey,TValue>.Gets a collection containing the values in the SortedList<TKey,TValue>.

Méthodes

Add(TKey, TValue) Add(TKey, TValue) Add(TKey, TValue) Add(TKey, TValue)

Ajoute un élément avec la clé et la valeur spécifiées dans SortedList<TKey,TValue>.Adds an element with the specified key and value into the SortedList<TKey,TValue>.

Clear() Clear() Clear() Clear()

Supprime tous les éléments de SortedList<TKey,TValue>.Removes all elements from the SortedList<TKey,TValue>.

ContainsKey(TKey) ContainsKey(TKey) ContainsKey(TKey) ContainsKey(TKey)

Détermine si SortedList<TKey,TValue> contient une clé spécifique.Determines whether the SortedList<TKey,TValue> contains a specific key.

ContainsValue(TValue) ContainsValue(TValue) ContainsValue(TValue) ContainsValue(TValue)

Détermine si SortedList<TKey,TValue> contient une valeur spécifique.Determines whether the SortedList<TKey,TValue> contains a specific value.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Détermine si l'objet spécifié est identique à l'objet actuel.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

Retourne un énumérateur qui itère au sein de SortedList<TKey,TValue>.Returns an enumerator that iterates through the SortedList<TKey,TValue>.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Fait office de fonction de hachage par défaut.Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Obtient le Type de l'instance actuelle.Gets the Type of the current instance.

(Inherited from Object)
IndexOfKey(TKey) IndexOfKey(TKey) IndexOfKey(TKey) IndexOfKey(TKey)

Recherche la clé spécifiée et retourne l'index de base zéro dans le SortedList<TKey,TValue> entier.Searches for the specified key and returns the zero-based index within the entire SortedList<TKey,TValue>.

IndexOfValue(TValue) IndexOfValue(TValue) IndexOfValue(TValue) IndexOfValue(TValue)

Recherche la valeur spécifiée et retourne l'index de base zéro de la première occurrence dans l'ensemble du SortedList<TKey,TValue>.Searches for the specified value and returns the zero-based index of the first occurrence within the entire SortedList<TKey,TValue>.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Crée une copie superficielle de l'objet Object actuel.Creates a shallow copy of the current Object.

(Inherited from Object)
Remove(TKey) Remove(TKey) Remove(TKey) Remove(TKey)

Supprime l'élément avec la clé spécifiée d'SortedList<TKey,TValue>.Removes the element with the specified key from the SortedList<TKey,TValue>.

RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32)

Supprime l'élément au niveau de l'index spécifié de SortedList<TKey,TValue>.Removes the element at the specified index of the SortedList<TKey,TValue>.

ToString() ToString() ToString() ToString()

Retourne une chaîne qui représente l'objet actuel.Returns a string that represents the current object.

(Inherited from Object)
TrimExcess() TrimExcess() TrimExcess() TrimExcess()

Définit la capacité au nombre réel d'éléments dans SortedList<TKey,TValue>, si ce nombre est inférieur à 90 pour cent de capacité actuelle.Sets the capacity to the actual number of elements in the SortedList<TKey,TValue>, if that number is less than 90 percent of current capacity.

TryGetValue(TKey, TValue) TryGetValue(TKey, TValue) TryGetValue(TKey, TValue) TryGetValue(TKey, TValue)

Obtient la valeur associée à la clé spécifiée.Gets the value associated with the specified key.

Implémentations d’interfaces explicites

ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32)

Copie les éléments de ICollection dans Array, à partir d'un index particulier de Array.Copies the elements of the ICollection to an Array, starting at a particular Array index.

ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized

Obtient une valeur indiquant si l'accès à ICollection est synchronisé (thread-safe).Gets a value indicating whether access to the ICollection is synchronized (thread safe).

ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot

Obtient un objet qui peut être utilisé pour synchroniser l'accès à ICollection.Gets an object that can be used to synchronize access to the ICollection.

ICollection<KeyValuePair<TKey,TValue>>.Add(KeyValuePair<TKey,TValue>) ICollection<KeyValuePair<TKey,TValue>>.Add(KeyValuePair<TKey,TValue>) ICollection<KeyValuePair<TKey,TValue>>.Add(KeyValuePair<TKey,TValue>) ICollection<KeyValuePair<TKey,TValue>>.Add(KeyValuePair<TKey,TValue>)

Ajoute une paire clé/valeur à ICollection<T>.Adds a key/value pair to the ICollection<T>.

ICollection<KeyValuePair<TKey,TValue>>.Contains(KeyValuePair<TKey,TValue>) ICollection<KeyValuePair<TKey,TValue>>.Contains(KeyValuePair<TKey,TValue>) ICollection<KeyValuePair<TKey,TValue>>.Contains(KeyValuePair<TKey,TValue>) ICollection<KeyValuePair<TKey,TValue>>.Contains(KeyValuePair<TKey,TValue>)

Détermine si ICollection<T> contient un élément spécifique.Determines whether the ICollection<T> contains a specific element.

ICollection<KeyValuePair<TKey,TValue>>.CopyTo(KeyValuePair<TKey,TValue>[], Int32) ICollection<KeyValuePair<TKey,TValue>>.CopyTo(KeyValuePair<TKey,TValue>[], Int32) ICollection<KeyValuePair<TKey,TValue>>.CopyTo(KeyValuePair<TKey,TValue>[], Int32) ICollection<KeyValuePair<TKey,TValue>>.CopyTo(KeyValuePair<TKey,TValue>[], Int32)

Copie les éléments de ICollection<T> dans Array, à partir d'un index particulier de Array.Copies the elements of the ICollection<T> to an Array, starting at a particular Array index.

ICollection<KeyValuePair<TKey,TValue>>.IsReadOnly ICollection<KeyValuePair<TKey,TValue>>.IsReadOnly ICollection<KeyValuePair<TKey,TValue>>.IsReadOnly ICollection<KeyValuePair<TKey,TValue>>.IsReadOnly

Obtient une valeur indiquant si ICollection<T> est en lecture seule.Gets a value indicating whether the ICollection<T> is read-only.

ICollection<KeyValuePair<TKey,TValue>>.Remove(KeyValuePair<TKey,TValue>) ICollection<KeyValuePair<TKey,TValue>>.Remove(KeyValuePair<TKey,TValue>) ICollection<KeyValuePair<TKey,TValue>>.Remove(KeyValuePair<TKey,TValue>) ICollection<KeyValuePair<TKey,TValue>>.Remove(KeyValuePair<TKey,TValue>)

Supprime de ICollection<T> la première occurrence d'une paire clé/valeur spécifique.Removes the first occurrence of a specific key/value pair from the ICollection<T>.

IDictionary.Add(Object, Object) IDictionary.Add(Object, Object) IDictionary.Add(Object, Object) IDictionary.Add(Object, Object)

Ajoute un élément avec la clé et la valeur fournies à IDictionary.Adds an element with the provided key and value to the IDictionary.

IDictionary.Contains(Object) IDictionary.Contains(Object) IDictionary.Contains(Object) IDictionary.Contains(Object)

Détermine si IDictionary contient un élément avec la clé spécifiée.Determines whether the IDictionary contains an element with the specified key.

IDictionary.GetEnumerator() IDictionary.GetEnumerator() IDictionary.GetEnumerator() IDictionary.GetEnumerator()

Retourne IDictionaryEnumerator pour l'objet IDictionary.Returns an IDictionaryEnumerator for the IDictionary.

IDictionary.IsFixedSize IDictionary.IsFixedSize IDictionary.IsFixedSize IDictionary.IsFixedSize

Obtient une valeur indiquant si IDictionary est de taille fixe.Gets a value indicating whether the IDictionary has a fixed size.

IDictionary.IsReadOnly IDictionary.IsReadOnly IDictionary.IsReadOnly IDictionary.IsReadOnly

Obtient une valeur indiquant si IDictionary est en lecture seule.Gets a value indicating whether the IDictionary is read-only.

IDictionary.Item[Object] IDictionary.Item[Object] IDictionary.Item[Object] IDictionary.Item[Object]

Obtient ou définit l'élément à l'aide de la clé spécifiée.Gets or sets the element with the specified key.

IDictionary.Keys IDictionary.Keys IDictionary.Keys IDictionary.Keys

Obtient un ICollection contenant les clés de IDictionary.Gets an ICollection containing the keys of the IDictionary.

IDictionary.Remove(Object) IDictionary.Remove(Object) IDictionary.Remove(Object) IDictionary.Remove(Object)

Supprime l'élément avec la clé spécifiée d'IDictionary.Removes the element with the specified key from the IDictionary.

IDictionary.Values IDictionary.Values IDictionary.Values IDictionary.Values

Obtient ICollection contenant les valeurs de IDictionary.Gets an ICollection containing the values in the IDictionary.

IDictionary<TKey,TValue>.Keys IDictionary<TKey,TValue>.Keys IDictionary<TKey,TValue>.Keys IDictionary<TKey,TValue>.Keys

Obtient un ICollection<T> contenant les clés de IDictionary<TKey,TValue>.Gets an ICollection<T> containing the keys of the IDictionary<TKey,TValue>.

IDictionary<TKey,TValue>.Values IDictionary<TKey,TValue>.Values IDictionary<TKey,TValue>.Values IDictionary<TKey,TValue>.Values

Obtient ICollection<T> contenant les valeurs de IDictionary<TKey,TValue>.Gets an ICollection<T> containing the values in the IDictionary<TKey,TValue>.

IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator()

Retourne un énumérateur qui itère au sein d’une collection.Returns an enumerator that iterates through a collection.

IEnumerable<KeyValuePair<TKey,TValue>>.GetEnumerator() IEnumerable<KeyValuePair<TKey,TValue>>.GetEnumerator() IEnumerable<KeyValuePair<TKey,TValue>>.GetEnumerator() IEnumerable<KeyValuePair<TKey,TValue>>.GetEnumerator()

Retourne un énumérateur qui itère au sein d’une collection.Returns an enumerator that iterates through a collection.

IReadOnlyDictionary<TKey,TValue>.Keys IReadOnlyDictionary<TKey,TValue>.Keys IReadOnlyDictionary<TKey,TValue>.Keys IReadOnlyDictionary<TKey,TValue>.Keys

Obtient une collection énumérable qui contient les clés dans dictionnaire en lecture seule.Gets an enumerable collection that contains the keys in the read-only dictionary.

IReadOnlyDictionary<TKey,TValue>.Values IReadOnlyDictionary<TKey,TValue>.Values IReadOnlyDictionary<TKey,TValue>.Values IReadOnlyDictionary<TKey,TValue>.Values

Obtient une collection énumérable qui contient les valeurs dans dictionnaire en lecture seule.Gets an enumerable collection that contains the values in the read-only dictionary.

Méthodes d’extension

GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey) GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey) GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey) GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey)
GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey, TValue) GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey, TValue) GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey, TValue) GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey, TValue)
Remove<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue) Remove<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue) Remove<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue) Remove<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue)
TryAdd<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue) TryAdd<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue) TryAdd<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue) TryAdd<TKey,TValue>(IDictionary<TKey,TValue>, TKey, TValue)
CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>) CopyToDataTable<T>(IEnumerable<T>)

Retourne un DataTable qui contient des copies des objets DataRow, à partir d'un objet d'entrée IEnumerable<T> où le paramètre générique T est DataRow.Returns a DataTable that contains copies of the DataRow objects, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption)

Copie les objets DataRow vers le DataTable spécifié, à partir d'un objet d'entrée IEnumerable<T> où le paramètre générique T est DataRow.Copies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler) CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler)

Copie les objets DataRow vers le DataTable spécifié, à partir d'un objet d'entrée IEnumerable<T> où le paramètre générique T est DataRow.Copies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

Effectue un cast des éléments d'un IEnumerable vers le type spécifié.Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

Filtre les éléments d'un IEnumerable en fonction du type spécifié.Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

Active la parallélisation d'une requête.Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

Convertit un IEnumerable en IQueryable.Converts an IEnumerable to an IQueryable.

Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>) Ancestors<T>(IEnumerable<T>)

Retourne une collection d'éléments qui contient les ancêtres de chaque nœud de la collection source.Returns a collection of elements that contains the ancestors of every node in the source collection.

Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName) Ancestors<T>(IEnumerable<T>, XName)

Retourne une collection d'éléments filtrée qui contient les ancêtres de chaque nœud de la collection source.Returns a filtered collection of elements that contains the ancestors of every node in the source collection. Seuls les éléments avec un XName correspondant sont inclus dans la collection.Only elements that have a matching XName are included in the collection.

DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>) DescendantNodes<T>(IEnumerable<T>)

Retourne une collection des nœuds descendants de chaque document et élément de la collection source.Returns a collection of the descendant nodes of every document and element in the source collection.

Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>) Descendants<T>(IEnumerable<T>)

Retourne une collection d'éléments qui contient les éléments descendants de tous les éléments et tous les documents de la collection source.Returns a collection of elements that contains the descendant elements of every element and document in the source collection.

Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName) Descendants<T>(IEnumerable<T>, XName)

Retourne une collection d'éléments filtrée qui contient les éléments descendants de tous les éléments et tous les documents de la collection source.Returns a filtered collection of elements that contains the descendant elements of every element and document in the source collection. Seuls les éléments avec un XName correspondant sont inclus dans la collection.Only elements that have a matching XName are included in the collection.

Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>) Elements<T>(IEnumerable<T>)

Retourne une collection des éléments enfants de chaque élément et document de la collection source.Returns a collection of the child elements of every element and document in the source collection.

Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName) Elements<T>(IEnumerable<T>, XName)

Retourne une collection filtrée des éléments enfants de chaque élément et document de la collection source.Returns a filtered collection of the child elements of every element and document in the source collection. Seuls les éléments avec un XName correspondant sont inclus dans la collection.Only elements that have a matching XName are included in the collection.

InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>) InDocumentOrder<T>(IEnumerable<T>)

Retourne une collection de nœuds qui contient tous les nœuds de la collection source, triés selon l'ordre des documents.Returns a collection of nodes that contains all nodes in the source collection, sorted in document order.

Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>) Nodes<T>(IEnumerable<T>)

Retourne une collection des nœuds enfants de chaque document et élément de la collection source.Returns a collection of the child nodes of every document and element in the source collection.

Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>) Remove<T>(IEnumerable<T>)

Supprime chaque nœud de la collection source de son nœud parent.Removes every node in the source collection from its parent node.

S’applique à

Cohérence de thread

Les membres statiques publics (Shared dans Visual Basic) de ce type sont thread-safe.Public static (Shared in Visual Basic) members of this type are thread safe. Il n'est pas garanti que les membres d'instance soient thread-safe.Any instance members are not guaranteed to be thread safe.

Un SortedList<TKey,TValue> peut prendre en charge plusieurs lecteurs simultanément, à condition que la collection ne soit pas modifiée.A SortedList<TKey,TValue> can support multiple readers concurrently, as long as the collection is not modified. Même dans ce cas, l’énumération d’une collection n’est intrinsèquement pas une procédure thread-safe.Even so, enumerating through a collection is intrinsically not a thread-safe procedure. Pour garantir la sécurité des threads pendant l'énumération, vous pouvez verrouiller la collection tout au long de cette opération.To guarantee thread safety during enumeration, you can lock the collection during the entire enumeration. Pour permettre à plusieurs threads d’accéder en lecture et en écriture à la collection, vous devez implémenter votre propre synchronisation.To allow the collection to be accessed by multiple threads for reading and writing, you must implement your own synchronization.

Voir aussi