PropertyCollection.System.Collections.IDictionary.Item プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > PropertyCollection.System.Collections.IDictionary.Item プロパティの意味・解説 

PropertyCollection.System.Collections.IDictionary.Item プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

指定したキー持つ要素取得または設定します

名前空間: System.DirectoryServices
アセンブリ: System.DirectoryServices (system.directoryservices.dll 内)
構文構文

Private Property System.Collections.IDictionary.Item
 ( _
    key As Object _
) As Object Implements IDictionary.Item
Dim instance As PropertyCollection
Dim key As Object
Dim value As Object

value = CType(instance, IDictionary).Item(key)

CType(instance, IDictionary).Item(key) = value
Object IDictionary.this [
    Object key
] { get; set; }
private:
virtual property Object^ System.Collections.IDictionary.Item [Object^] {
    Object^ get (Object^ key) sealed = IDictionary::default::get;
    void set (Object^ key, Object^ value) sealed
 = IDictionary::default::set;
}

パラメータ

key

取得または設定する要素キー

プロパティ
指定したキー持つ要素

例外例外
例外種類条件

ArgumentNullException

keynull 参照 (Visual Basic では Nothing) です。

NotSupportedException

このプロパティ設定されていますが、IDictionary オブジェクト読み取り専用です。

または

このプロパティ設定されていますが、keyコレクション内に存在しません。また、IDictionary固定サイズです。

解説解説

このプロパティでは、myCollection[key] という構文使用してコレクション内の特定の要素アクセスできます

Item プロパティ使用すると、ディクショナリ内に存在しないキーの値を設定することで、新し要素追加することもできます (例 : myCollection["myNonexistentKey"] = myValue)。ただし、指定したキーがディクショナリに既に存在する場合Item プロパティ設定すると、既存の値が上書きされます対照的にAdd メソッド既存要素変更しません。

使用例使用例

Item プロパティ実装する方法の例を次に示します。このコード例は、IDictionary クラストピック取り上げているコード例一部です。

Public Property Item(ByVal
 key As Object) As Object
 Implements IDictionary.Item
    Get

        ' If this key is in the dictionary, return its value.
        Dim index As Integer
        If TryGetIndexOfKey(key, index) Then

            ' The key was found return its value.
            Return items(index).Value
        Else

            ' The key was not found return null.
            Return Nothing
        End If
    End Get

    Set(ByVal value As Object)
        ' If this key is in the dictionary, change its value. 
        Dim index As Integer
        If TryGetIndexOfKey(key, index) Then

            ' The key was found change its value.
            items(index).Value = value
        Else

            ' This key is not in the dictionary add this key/value pair.
            Add(key, value)
        End If
    End Set
End Property
public object this[object key]
{
    get
    {   
        // If this key is in the dictionary, return its value.
        Int32 index;
        if (TryGetIndexOfKey(key, out index))
        {
            // The key was found; return its value.
            return items[index].Value;
        } 
        else
        {
            // The key was not found; return null.
            return null;
        }
    }

    set
    {
        // If this key is in the dictionary, change its value. 
        Int32 index;
        if (TryGetIndexOfKey(key, out index))
        {
            // The key was found; change its value.
            items[index].Value = value;
        } 
        else
        {
            // This key is not in the dictionary; add this key/value
 pair.
            Add(key, value);
        }
    }
}
public:
    virtual property Object^ default[Object^]
    {
        Object^ get(Object^ key)
        {
            // If this key is in the dictionary, return its value.
            int index;
            if (TryGetIndexOfKey(key, &index))
            {
                // The key was found; return its value.
                return items[index]->Value;
            }
            else
            {
                // The key was not found; return null.
                return nullptr;
            }
        }

        void set(Object^ key, Object^ value)
        {
            // If this key is in the dictionary, change its value.
            int index;
            if (TryGetIndexOfKey(key, &index))
            {
                // The key was found; change its value.
                items[index]->Value = value;
            }
            else
            {
                // This key is not in the dictionary; add this
                // key/value pair.
                Add(key, value);
            }
        }
    }
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からPropertyCollection.System.Collections.IDictionary.Item プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からPropertyCollection.System.Collections.IDictionary.Item プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からPropertyCollection.System.Collections.IDictionary.Item プロパティ を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

PropertyCollection.System.Collections.IDictionary.Item プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



PropertyCollection.System.Collections.IDictionary.Item プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS