DictionaryEntry Yapı
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Ayarlanabilen veya alınabilen bir sözlük anahtarı/değer çifti tanımlar.
public value class DictionaryEntry
public struct DictionaryEntry
[System.Serializable]
public struct DictionaryEntry
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public struct DictionaryEntry
type DictionaryEntry = struct
[<System.Serializable>]
type DictionaryEntry = struct
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type DictionaryEntry = struct
Public Structure DictionaryEntry
- Devralma
- Öznitelikler
Örnekler
Aşağıdaki örnek, bir DictionaryEntry nesne üzerinden yinelemek için öğesinin kullanımını Hashtable gösterir.
// A simple example for the DictionaryEntry structure.
using System;
using System.Collections;
class Example
{
public static void Main()
{
// Create a new hash table.
//
Hashtable openWith = new Hashtable();
// Add some elements to the hash table. 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");
// When you use foreach to enumerate hash table elements,
// the elements are retrieved as DictionaryEntry objects.
Console.WriteLine();
foreach (DictionaryEntry de in openWith)
{
Console.WriteLine("Key = {0}, Value = {1}", de.Key, de.Value);
}
}
}
/* This code example produces output similar to the following:
Key = rtf, Value = wordpad.exe
Key = txt, Value = notepad.exe
Key = dib, Value = paint.exe
Key = bmp, Value = paint.exe
*/
'A simple example for the DictionaryEntry structure.
Imports System.Collections
Module Example
Sub Main()
' Create a new hash table.
'
Dim openWith As New Hashtable()
' Add some elements to the hash table. 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")
' When you use For Each to enumerate hash table elements,
' the elements are retrieved as DictionaryEntry objects.
Console.WriteLine()
For Each de As DictionaryEntry In openWith
Console.WriteLine("Key = {0}, Value = {1}", _
de.Key, de.Value)
Next de
End Sub
End Module
' This code example produces output similar to the following:
'
'Key = rtf, Value = wordpad.exe
'Key = txt, Value = notepad.exe
'Key = dib, Value = paint.exe
'Key = bmp, Value = paint.exe
Açıklamalar
IDictionaryEnumerator.Entry yöntemi bu türün bir örneğini döndürür.
Important
Yapıyı DictionaryEntry yeni geliştirme için kullanmanızı önermiyoruz. Bunun yerine, sınıfıyla KeyValuePair<TKey,TValue> birlikte genel Dictionary<TKey,TValue> bir yapı kullanmanızı öneririz. Daha fazla bilgi için bkz. GitHub'da genel olmayan koleksiyonlar kullanılmamalıdır .
C# foreach deyimi ve Visual Basic For Each deyimi koleksiyondaki her öğenin türünü gerektirir. öğesinin IDictionary 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. Örneğin:
foreach (DictionaryEntry de in openWith)
{
Console.WriteLine("Key = {0}, Value = {1}", de.Key, de.Value);
}
For Each de As DictionaryEntry In openWith
Console.WriteLine("Key = {0}, Value = {1}", _
de.Key, de.Value)
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 |
|---|---|
| DictionaryEntry(Object, Object) |
Belirtilen anahtar ve değerle türünün bir örneğini DictionaryEntry başlatır. |
Özellikler
| Name | Description |
|---|---|
| Key |
Anahtar/değer çiftindeki anahtarı alır veya ayarlar. |
| Value |
Anahtar/değer çiftindeki değeri alır veya ayarlar. |
Yöntemler
| Name | Description |
|---|---|
| Deconstruct(Object, Object) |
Geçerli DictionaryEntryöğesinin yapısını kaldırıyor. |