PropertyCollection.System.Collections.IDictionary.Item プロパティ
アセンブリ: 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
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; }
プロパティ値
指定したキーを持つ要素。


このプロパティでは、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); } } }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からPropertyCollection.System.Collections.IDictionary.Item プロパティを検索する場合は、下記のリンクをクリックしてください。

- PropertyCollection.System.Collections.IDictionary.Item プロパティのページへのリンク