DictionaryEntry DictionaryEntry DictionaryEntry DictionaryEntry Struct

定義

設定または取得できる、ディクショナリのキー/値ペアを定義します。Defines a dictionary key/value pair that can be set or retrieved.

public value class DictionaryEntry
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public struct DictionaryEntry
type DictionaryEntry = struct
Public Structure DictionaryEntry
継承
DictionaryEntryDictionaryEntryDictionaryEntryDictionaryEntry
属性

使用例を次に示しますDictionaryEntryを反復処理する、Hashtableオブジェクト。The following example demonstrates the use of DictionaryEntry to iterate through a Hashtable object.

// A simple example for the DictionaryEntry structure.
using namespace System;
using namespace System::Collections;

public ref class Example
{
public:
    static void Main()
    {
        // Create a new hash table.
        //
        Hashtable^ openWith = gcnew 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();
        for each (DictionaryEntry de in openWith)
        {
            Console::WriteLine("Key = {0}, Value = {1}", de.Key, de.Value);
        }
    }
};

int main()
{
    Example::Main();
}

/* 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.
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
Imports System.Collections
Imports Microsoft.VisualBasic

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

注釈

IDictionaryEnumerator.Entryメソッドは、この型のインスタンスを返します。The IDictionaryEnumerator.Entry method returns an instance of this type.

重要

使用することをお勧めしません、DictionaryEntry新規の開発の構造体。We don't recommend that you use the DictionaryEntry structure for new development. ジェネリックを使用すること勧め代わりに、KeyValuePair<TKey,TValue>と共に構造体、Dictionary<TKey,TValue>クラス。Instead, we recommend that you use a generic KeyValuePair<TKey,TValue> structure along with the Dictionary<TKey,TValue> class. 詳細については、次を参照してください。非ジェネリック コレクションを使用してはならないGitHub でします。For more information, see Non-generic collections shouldn't be used on GitHub.

C# Foreachステートメントと Visual Basicステートメントは、コレクション内の各要素の型を必要とします。The C# foreach statement and the Visual Basic For Each statement require the type of each element in the collection. 以降の各要素、IDictionaryキー/値のペアは、要素の型がないと、キーの型または値の型。Since each element of the IDictionary is a key/value pair, the element type is not the type of the key or the type of the value. 要素の型は、代わりに、DictionaryEntryします。Instead, the element type is DictionaryEntry. 次に例を示します。For example:

for each (DictionaryEntry de in openWith)
{
    Console::WriteLine("Key = {0}, Value = {1}", de.Key, de.Value);
}
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

foreachステートメントは、コレクションを記述しないからの読み取りのみを許可する列挙子のラッパーです。The foreach statement is a wrapper around the enumerator, which only allows reading from, not writing to, the collection.

コンストラクター

DictionaryEntry(Object, Object) DictionaryEntry(Object, Object) DictionaryEntry(Object, Object) DictionaryEntry(Object, Object)

指定したキーと値を使用して、DictionaryEntry 型のインスタンスを初期化します。Initializes an instance of the DictionaryEntry type with the specified key and value.

プロパティ

Key Key Key Key

キー/値ペア内のキーを取得または設定します。Gets or sets the key in the key/value pair.

Value Value Value Value

キー/値ペア内の値を取得または設定します。Gets or sets the value in the key/value pair.

メソッド

Deconstruct(Object, Object) Deconstruct(Object, Object) Deconstruct(Object, Object) Deconstruct(Object, Object)

適用対象

こちらもご覧ください