英語で読む

次の方法で共有


DictionaryEntry 構造体

定義

設定または取得できる、ディクショナリのキー/値ペアを定義します。

C#
public struct DictionaryEntry
C#
[System.Serializable]
public struct DictionaryEntry
C#
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public struct DictionaryEntry
継承
DictionaryEntry
属性

次の例では、 を使用 DictionaryEntry して オブジェクトを反復処理 Hashtable します。

C#
// 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
 */

注釈

メソッドは IDictionaryEnumerator.Entry 、この型のインスタンスを返します。

重要

新しい開発に 構造体を DictionaryEntry 使用することはお勧めしません。 代わりに、 クラスと共Dictionary<TKey,TValue>にジェネリックKeyValuePair<TKey,TValue>構造体を使用することをお勧めします。 詳細については、「GitHub で 非ジェネリック コレクションを使用しないでください 」を参照してください。

C# foreach ステートメントと Visual Basic For Each ステートメントには 、コレクション内の各要素の型が必要です。 の IDictionary 各要素はキーと値のペアであるため、要素の型はキーの型または値の型ではありません。 代わりに、要素の型は です DictionaryEntry。 次に例を示します。

C#
foreach (DictionaryEntry de in openWith)
{
    Console.WriteLine("Key = {0}, Value = {1}", de.Key, de.Value);
}

ステートメントは foreach 列挙子を囲むラッパーであり、コレクションの書き込みではなく、コレクションからの読み取りのみを許可します。

コンストラクター

DictionaryEntry(Object, Object)

指定したキーと値を使用して、DictionaryEntry 型のインスタンスを初期化します。

プロパティ

Key

キー/値ペア内のキーを取得または設定します。

Value

キー/値ペア内の値を取得または設定します。

メソッド

Deconstruct(Object, Object)

現在の DictionaryEntry を分解します。

適用対象

製品 バージョン
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

こちらもご覧ください