OrderedDictionary Sınıf

Tanım

Anahtar veya dizin tarafından erişilebilen anahtar/değer çiftleri koleksiyonunu temsil eder.

public ref class OrderedDictionary : System::Collections::IDictionary, System::Collections::Specialized::IOrderedDictionary
public ref class OrderedDictionary : System::Collections::IDictionary, System::Collections::Specialized::IOrderedDictionary, System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable
public ref class OrderedDictionary : System::Collections::Specialized::IOrderedDictionary, System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable
public class OrderedDictionary : System.Collections.IDictionary, System.Collections.Specialized.IOrderedDictionary
public class OrderedDictionary : System.Collections.IDictionary, System.Collections.Specialized.IOrderedDictionary, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
[System.Serializable]
public class OrderedDictionary : System.Collections.IDictionary, System.Collections.Specialized.IOrderedDictionary, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
public class OrderedDictionary : System.Collections.Specialized.IOrderedDictionary, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
type OrderedDictionary = class
    interface ICollection
    interface IEnumerable
    interface IDictionary
    interface IOrderedDictionary
type OrderedDictionary = class
    interface ICollection
    interface IEnumerable
    interface IDictionary
    interface IOrderedDictionary
    interface IDeserializationCallback
    interface ISerializable
type OrderedDictionary = class
    interface ICollection
    interface IEnumerable
    interface IDictionary
    interface IOrderedDictionary
    interface ISerializable
    interface IDeserializationCallback
[<System.Serializable>]
type OrderedDictionary = class
    interface IOrderedDictionary
    interface IDictionary
    interface ICollection
    interface IEnumerable
    interface ISerializable
    interface IDeserializationCallback
Public Class OrderedDictionary
Implements IDictionary, IOrderedDictionary
Public Class OrderedDictionary
Implements IDeserializationCallback, IDictionary, IOrderedDictionary, ISerializable
Public Class OrderedDictionary
Implements IDeserializationCallback, IOrderedDictionary, ISerializable
Devralma
OrderedDictionary
Türetilmiş
Öznitelikler
Uygulamalar

Örnekler

Aşağıdaki kod örneği, bir OrderedDictionary koleksiyonun oluşturulmasını, popülasyonunu ve değiştirilmesini ve ayrıca öğesinin içeriğini OrderedDictionarygörüntülemeye yönelik iki tekniği gösterir: biri ve Keys özelliklerini, Values diğeri ise yöntemi aracılığıyla GetEnumerator bir numaralandırıcı oluşturur.

// The following code example enumerates the elements of a OrderedDictionary.
using System;
using System.Collections;
using System.Collections.Specialized;

public class OrderedDictionarySample
{
    public static void Main()
    {

        // Creates and initializes a OrderedDictionary.
        OrderedDictionary myOrderedDictionary = new OrderedDictionary();
        myOrderedDictionary.Add("testKey1", "testValue1");
        myOrderedDictionary.Add("testKey2", "testValue2");
        myOrderedDictionary.Add("keyToDelete", "valueToDelete");
        myOrderedDictionary.Add("testKey3", "testValue3");

        ICollection keyCollection = myOrderedDictionary.Keys;
        ICollection valueCollection = myOrderedDictionary.Values;

        // Display the contents using the key and value collections
        DisplayContents(keyCollection, valueCollection, myOrderedDictionary.Count);

        // Modifying the OrderedDictionary
        if (!myOrderedDictionary.IsReadOnly)
        {
            // Insert a new key to the beginning of the OrderedDictionary
            myOrderedDictionary.Insert(0, "insertedKey1", "insertedValue1");

            // Modify the value of the entry with the key "testKey2"
            myOrderedDictionary["testKey2"] = "modifiedValue";

            // Remove the last entry from the OrderedDictionary: "testKey3"
            myOrderedDictionary.RemoveAt(myOrderedDictionary.Count - 1);

            // Remove the "keyToDelete" entry, if it exists
            if (myOrderedDictionary.Contains("keyToDelete"))
            {
                myOrderedDictionary.Remove("keyToDelete");
            }
        }

        Console.WriteLine(
            "{0}Displaying the entries of a modified OrderedDictionary.",
            Environment.NewLine);
        DisplayContents(keyCollection, valueCollection, myOrderedDictionary.Count);

        // Clear the OrderedDictionary and add new values
        myOrderedDictionary.Clear();
        myOrderedDictionary.Add("newKey1", "newValue1");
        myOrderedDictionary.Add("newKey2", "newValue2");
        myOrderedDictionary.Add("newKey3", "newValue3");

        // Display the contents of the "new" Dictionary using an enumerator
        IDictionaryEnumerator myEnumerator =
            myOrderedDictionary.GetEnumerator();

        Console.WriteLine(
            "{0}Displaying the entries of a \"new\" OrderedDictionary.",
            Environment.NewLine);

        DisplayEnumerator(myEnumerator);
    }

    // Displays the contents of the OrderedDictionary from its keys and values
    public static void DisplayContents(
        ICollection keyCollection, ICollection valueCollection, int dictionarySize)
    {
        String[] myKeys = new String[dictionarySize];
        String[] myValues = new String[dictionarySize];
        keyCollection.CopyTo(myKeys, 0);
        valueCollection.CopyTo(myValues, 0);

        // Displays the contents of the OrderedDictionary
        Console.WriteLine("   INDEX KEY                       VALUE");
        for (int i = 0; i < dictionarySize; i++)
        {
            Console.WriteLine("   {0,-5} {1,-25} {2}",
                i, myKeys[i], myValues[i]);
        }
        Console.WriteLine();
    }

    // Displays the contents of the OrderedDictionary using its enumerator
    public static void DisplayEnumerator(IDictionaryEnumerator myEnumerator)
    {
        Console.WriteLine("   KEY                       VALUE");
        while (myEnumerator.MoveNext())
        {
            Console.WriteLine("   {0,-25} {1}",
                myEnumerator.Key, myEnumerator.Value);
        }
    }
}

/*
This code produces the following output.

   INDEX KEY                       VALUE
   0     testKey1                  testValue1
   1     testKey2                  testValue2
   2     keyToDelete               valueToDelete
   3     testKey3                  testValue3


Displaying the entries of a modified OrderedDictionary.
   INDEX KEY                       VALUE
   0     insertedKey1              insertedValue1
   1     testKey1                  testValue1
   2     testKey2                  modifiedValue


Displaying the entries of a "new" OrderedDictionary.
   KEY                       VALUE
   newKey1                   newValue1
   newKey2                   newValue2
   newKey3                   newValue3

*/
' The following code example enumerates the elements of a OrderedDictionary.
Imports System.Collections
Imports System.Collections.Specialized

Public Class OrderedDictionarySample

    Public Shared Sub Main()

        ' Creates and initializes a OrderedDictionary.
        Dim myOrderedDictionary As New OrderedDictionary()
        myOrderedDictionary.Add("testKey1", "testValue1")
        myOrderedDictionary.Add("testKey2", "testValue2")
        myOrderedDictionary.Add("keyToDelete", "valueToDelete")
        myOrderedDictionary.Add("testKey3", "testValue3")

        Dim keyCollection As ICollection = myOrderedDictionary.Keys
        Dim valueCollection As ICollection = myOrderedDictionary.Values

        ' Display the contents Imports the key and value collections
        DisplayContents( _
            keyCollection, valueCollection, myOrderedDictionary.Count)

        ' Modifying the OrderedDictionary
        If Not myOrderedDictionary.IsReadOnly Then

            ' Insert a new key to the beginning of the OrderedDictionary
            myOrderedDictionary.Insert(0, "insertedKey1", "insertedValue1")

            ' Modify the value of the entry with the key "testKey2"
            myOrderedDictionary("testKey2") = "modifiedValue"

            ' Remove the last entry from the OrderedDictionary: "testKey3"
            myOrderedDictionary.RemoveAt(myOrderedDictionary.Count - 1)

            ' Remove the "keyToDelete" entry, if it exists
            If (myOrderedDictionary.Contains("keyToDelete")) Then
                myOrderedDictionary.Remove("keyToDelete")
            End If
        End If

        Console.WriteLine( _
            "{0}Displaying the entries of a modified OrderedDictionary.", _
            Environment.NewLine)
        DisplayContents( _
            keyCollection, valueCollection, myOrderedDictionary.Count)

        ' Clear the OrderedDictionary and add new values
        myOrderedDictionary.Clear()
        myOrderedDictionary.Add("newKey1", "newValue1")
        myOrderedDictionary.Add("newKey2", "newValue2")
        myOrderedDictionary.Add("newKey3", "newValue3")

        ' Display the contents of the "new" Dictionary Imports an enumerator
        Dim myEnumerator As IDictionaryEnumerator = _
            myOrderedDictionary.GetEnumerator()

        Console.WriteLine( _
            "{0}Displaying the entries of a 'new' OrderedDictionary.", _
            Environment.NewLine)

        DisplayEnumerator(myEnumerator)
    End Sub

    ' Displays the contents of the OrderedDictionary from its keys and values
    Public Shared Sub DisplayContents( _
        ByVal keyCollection As ICollection, _
        ByVal valueCollection As ICollection, ByVal dictionarySize As Integer)

        Dim myKeys(dictionarySize) As [String]
        Dim myValues(dictionarySize) As [String]
        keyCollection.CopyTo(myKeys, 0)
        valueCollection.CopyTo(myValues, 0)

        ' Displays the contents of the OrderedDictionary
        Console.WriteLine("   INDEX KEY                       VALUE")
        Dim i As Integer
        For i = 0 To dictionarySize - 1
            Console.WriteLine("   {0,-5} {1,-25} {2}", _
                 i, myKeys(i), myValues(i))
        Next i
        Console.WriteLine()
    End Sub

    ' Displays the contents of the OrderedDictionary using its enumerator
    Public Shared Sub DisplayEnumerator( _
        ByVal myEnumerator As IDictionaryEnumerator)

        Console.WriteLine("   KEY                       VALUE")
        While myEnumerator.MoveNext()
            Console.WriteLine("   {0,-25} {1}", _
                myEnumerator.Key, myEnumerator.Value)
        End While
    End Sub
End Class

'This code produces the following output.
'
'   INDEX KEY                       VALUE
'0:              testKey1(testValue1)
'1:              testKey2(testValue2)
'2:              keyToDelete(valueToDelete)
'3:              testKey3(testValue3)
'
'
'Displaying the entries of a modified OrderedDictionary.
'   INDEX KEY                       VALUE
'0:              insertedKey1(insertedValue1)
'1:              testKey1(testValue1)
'2:              testKey2(modifiedValue)
'
'
'Displaying the entries of a "new" OrderedDictionary.
'                KEY(VALUE)
'                newKey1(newValue1)
'                newKey2(newValue2)
'                newKey3(newValue3)

Açıklamalar

Her öğe bir nesnede depolanan bir DictionaryEntry anahtar/değer çiftidir. Anahtar olamaz null, ancak bir değer olabilir.

öğesinin OrderedDictionary öğeleri, sınıfın SortedDictionary<TKey,TValue> öğelerinin aksine anahtara göre sıralanmaz. Öğelere anahtardan veya dizinden erişebilirsiniz.

C# dilinin foreach deyimi (Visual Basic'da For Each), koleksiyondaki her öğenin türünde olan nesneleri döndürür. Koleksiyonun OrderedDictionary her öğesi bir anahtar/değer çifti olduğundan, öğe türü anahtarın türü veya değerin türü değildir. Bunun yerine, öğe türü şeklindedir DictionaryEntry. Aşağıdaki kod söz dizimini gösterir.

foreach (DictionaryEntry de in myOrderedDictionary)
{
    //...
}
For Each de As DictionaryEntry In myOrderedDictionary
    '...
Next de

deyimi foreach , numaralandırıcının etrafındaki bir sarmalayıcıdır ve yalnızca koleksiyonun okunmasına izin verir, yazmaya değil.

Oluşturucular

Name Description
OrderedDictionary()

OrderedDictionary sınıfının yeni bir örneğini başlatır.

OrderedDictionary(IEqualityComparer)

Belirtilen karşılaştırıcıyı kullanarak sınıfın OrderedDictionary yeni bir örneğini başlatır.

OrderedDictionary(Int32, IEqualityComparer)

Belirtilen ilk kapasiteyi ve karşılaştırıcıyı OrderedDictionary kullanarak sınıfın yeni bir örneğini başlatır.

OrderedDictionary(Int32)

Belirtilen ilk kapasiteyi kullanarak sınıfın OrderedDictionary yeni bir örneğini başlatır.

OrderedDictionary(SerializationInfo, StreamingContext)
Geçersiz.

Belirtilen OrderedDictionary ve SerializationInfo nesnelerini kullanarak serileştirilebilir sınıfının yeni bir örneğini StreamingContext başlatır.

Özellikler

Name Description
Count

Koleksiyonda yer alan OrderedDictionary anahtar/değer çiftlerinin sayısını alır.

IsReadOnly

Koleksiyonun OrderedDictionary salt okunur olup olmadığını belirten bir değer alır.

Item[Int32]

Belirtilen dizindeki değeri alır veya ayarlar.

Item[Object]

Belirtilen anahtarla değeri alır veya ayarlar.

Keys

Koleksiyondaki ICollection anahtarları içeren bir OrderedDictionary nesne alır.

Values

Koleksiyondaki ICollection değerleri içeren bir OrderedDictionary nesne alır.

Yöntemler

Name Description
Add(Object, Object)

Kullanılabilir en düşük dizine sahip koleksiyona belirtilen anahtara ve değere OrderedDictionary sahip bir girdi ekler.

AsReadOnly()

Geçerli OrderedDictionary koleksiyonun salt okunur bir kopyasını döndürür.

Clear()

Koleksiyondaki OrderedDictionary tüm öğeleri kaldırır.

Contains(Object)

Koleksiyonun OrderedDictionary belirli bir anahtar içerip içermediğini belirler.

CopyTo(Array, Int32)

Öğeleri belirtilen dizindeki OrderedDictionary tek boyutlu Array bir nesneye kopyalar.

Equals(Object)

Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler.

(Devralındığı yer: Object)
GetEnumerator()

Koleksiyonda IDictionaryEnumerator yineleyen bir OrderedDictionary nesne döndürür.

GetHashCode()

Varsayılan karma işlevi işlevi görür.

(Devralındığı yer: Object)
GetObjectData(SerializationInfo, StreamingContext)
Geçersiz.

Arabirimini ISerializable uygular ve koleksiyonu serileştirmek OrderedDictionary için gereken verileri döndürür.

GetType()

Geçerli örneğin Type alır.

(Devralındığı yer: Object)
Insert(Int32, Object, Object)

Belirtilen dizinde OrderedDictionary belirtilen anahtar ve değerle koleksiyona yeni bir giriş ekler.

MemberwiseClone()

Geçerli Objectbasit bir kopyasını oluşturur.

(Devralındığı yer: Object)
OnDeserialization(Object)

arabirimini ISerializable uygular ve seri durumdan çıkarma tamamlandığında seri durumdan çıkarma olayı tarafından geri çağrılır.

Remove(Object)

Belirtilen anahtara sahip girdiyi koleksiyondan OrderedDictionary kaldırır.

RemoveAt(Int32)

Belirtilen dizindeki girdiyi koleksiyondan OrderedDictionary kaldırır.

ToString()

Geçerli nesneyi temsil eden bir dize döndürür.

(Devralındığı yer: Object)

Belirtik Arabirim Kullanımları

Name Description
ICollection.IsSynchronized

Nesneye erişimin OrderedDictionary eşitlenip eşitlenmediğini belirten bir değer alır (iş parçacığı güvenli).

ICollection.SyncRoot

Nesneye erişimi OrderedDictionary eşitlemek için kullanılabilecek bir nesne alır.

IDeserializationCallback.OnDeserialization(Object)

arabirimini ISerializable uygular ve seri durumdan çıkarma tamamlandığında seri durumdan çıkarma olayı tarafından geri çağrılır.

IDictionary.IsFixedSize

değerinin sabit bir boyuta sahip olup olmadığını OrderedDictionary belirten bir değer alır.

IEnumerable.GetEnumerator()

Koleksiyonda IDictionaryEnumerator yineleyen bir OrderedDictionary nesne döndürür.

Uzantı Metotları

Name Description
AsParallel(IEnumerable)

Sorgunun paralelleştirilmesini etkinleştirir.

AsQueryable(IEnumerable)

bir IEnumerable öğesine IQueryabledönüştürür.

Cast<TResult>(IEnumerable)

öğesinin IEnumerable öğelerini belirtilen türe yazar.

OfType<TResult>(IEnumerable)

Belirtilen türe göre bir IEnumerable öğesinin öğelerini filtreler.

Şunlara uygulanır