Dictionary.System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>.Remove メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > Dictionary.System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>.Remove メソッドの意味・解説 

Dictionary.System.Collections.Generic.ICollection>.Remove メソッド

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

ディクショナリからキーと値を削除します

名前空間: System.Collections.Generic
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Private Function System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>.Remove
 ( _
    keyValuePair As KeyValuePair(Of TKey, TValue)
 _
) As Boolean Implements
 ICollection(Of KeyValuePair(Of TKey, TValue)).Remove
Dim instance As Dictionary(Of
 TKey, TValue)
Dim keyValuePair As KeyValuePair(Of
 TKey, TValue)
Dim returnValue As Boolean

returnValue = CType(instance, ICollection(Of KeyValuePair(Of
 TKey, TValue))).Remove(keyValuePair)
bool ICollection<KeyValuePair<TKey,TValue>>.Remove
 (
    KeyValuePair<TKey,TValue> keyValuePair
)
private:
virtual bool System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>.Remove
 (
    KeyValuePair<TKey, TValue> keyValuePair
) sealed = ICollection<KeyValuePair<TKey, TValue>>::Remove

パラメータ

keyValuePair

Dictionary から削除するキーと値を表す KeyValuePair 構造体

戻り値
keyValuePair表されキーと値が見つかり、正常に削除され場合trueそれ以外場合false。このメソッドは、keyValuePair が ICollection に見つからない場合false返します

解説解説
使用例使用例

System.Collections.Generic.ICollection ジェネリック インターフェイスの System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>.Add、System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>.Contains、System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>.CopyTo、および System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>.Remove の各メソッド使用してDictionary オブジェクト操作する方法次のコード例示します

Imports System
Imports System.Collections.Generic

Public Class Example
    
    Public Shared Sub Main()
 

        ' Create a new dictionary of strings, with string keys, and
        ' access it through the generic ICollection interface. The
        ' generic ICollection interface views the dictionary as a
        ' collection of KeyValuePair objects with the same type
        ' arguments as the dictionary.
        '
        Dim openWith As ICollection(Of
 KeyValuePair(Of String, String))
 _
            = New Dictionary(Of String,
 String)
        
        ' Add some elements to the dictionary. When elements are 
        ' added through the ICollection(Of T) interface, the keys
        ' and values must be wrapped in KeyValuePair objects.
        '
        openWith.Add(New KeyValuePair(Of String,String)("txt",
 "notepad.exe"))
        openWith.Add(New KeyValuePair(Of String,String)("bmp",
 "paint.exe"))
        openWith.Add(New KeyValuePair(Of String,String)("dib",
 "paint.exe"))
        openWith.Add(New KeyValuePair(Of String,String)("rtf",
 "wordpad.exe"))
        
        Console.WriteLine()
        For Each element As
 KeyValuePair(Of String, String)
 in openWith
            Console.WriteLine("{0}, {1}", element.Key,
 element.Value)
        Next
           
        ' The Contains method also takes a KeyValuePair object.
        '
        Console.WriteLine(vbLf & _
            "Contains(KeyValuePair(""txt"",
 ""notepad.exe"")):
 {0}", _
            openWith.Contains(New KeyValuePair(Of
 String,String)("txt", "notepad.exe")))

        ' The Remove method takes a KeyValuePair object.)
        '
        ' Use the Remove method to remove a key/value pair.
        Console.WriteLine(vbLf &  _
            "Remove(New KeyValuePair(""dib"",
 ""paint.exe""))")
        openWith.Remove(New KeyValuePair(Of
 String,String)("dib", "paint.exe"))
        
        Console.WriteLine()
        For Each element As
 KeyValuePair(Of String, String)
 in openWith
            Console.WriteLine("{0}, {1}", element.Key,
 element.Value)
        Next

        ' Create an array of KeyValuePair objects and copy the 
        ' contents of the dictionary to it. Subtract one from the
        ' array size because Visual Basic allocates an extra array
        ' element.
        Dim copy(openWith.Count - 1) As KeyValuePair(Of
 String, String)
        openWith.CopyTo(copy, 0)
    
        ' List the contents of the array.
        '
        Console.WriteLine()
        For Each element As
 KeyValuePair(Of String, String)
 in copy
            Console.WriteLine("{0}, {1}", element.Key,
 element.Value)
        Next

    End Sub

End Class

' This code example produces the following output:
'
'txt, notepad.exe
'bmp, paint.exe
'dib, paint.exe
'rtf, wordpad.exe
'
'Contains(KeyValuePair("txt", "notepad.exe")): True
'
'Remove(New KeyValuePair("dib", "paint.exe"))
'
'txt, notepad.exe
'bmp, paint.exe
'rtf, wordpad.exe
'
'txt, notepad.exe
'bmp, paint.exe
'rtf, wordpad.exe 
using System;
using System.Collections.Generic;

public class Example
{
    public static void Main()
    {
        // Create a new dictionary of strings, with string keys, and
        // access it through the generic ICollection interface. The
        // generic ICollection interface views the dictionary as a
        // collection of KeyValuePair objects with the same type
        // arguments as the dictionary.
        //
        ICollection<KeyValuePair<String, String>> openWith =
            new Dictionary<String, String>();
        
        // Add some elements to the dictionary. When elements are 
        // added through the ICollection<T> interface, the keys
        // and values must be wrapped in KeyValuePair objects.
        //
        openWith.Add(new KeyValuePair<String,String>("txt",
 "notepad.exe"));
        openWith.Add(new KeyValuePair<String,String>("bmp",
 "paint.exe"));
        openWith.Add(new KeyValuePair<String,String>("dib",
 "paint.exe"));
        openWith.Add(new KeyValuePair<String,String>("rtf",
 "wordpad.exe"));
        
        Console.WriteLine();
        foreach( KeyValuePair<string, string>
 element in openWith )
        {
            Console.WriteLine("{0}, {1}", element.Key, element.Value);
        }
           
        // The Contains method also takes a KeyValuePair object.
        //
        Console.WriteLine(
            "\nContains(KeyValuePair(\"txt\", \"notepad.exe\")):
 {0}", 
            openWith.Contains(new KeyValuePair<String,String>("txt",
 "notepad.exe")));

        // The Remove method takes a KeyValuePair object.)
        //
        // Use the Remove method to remove a key/value pair.
        Console.WriteLine("\nRemove(new KeyValuePair(\"dib\",
 \"paint.exe\"))");
        openWith.Remove(new KeyValuePair<String,String>("dib",
 "paint.exe"));
        
        Console.WriteLine();
        foreach( KeyValuePair<string, string>
 element in openWith )
        {
            Console.WriteLine("{0}, {1}", element.Key, element.Value);
        }

        // Create an array of KeyValuePair objects and copy the 
        // contents of the dictionary to it. 
        // 
        KeyValuePair<string, string>[]
 copy = 
            new KeyValuePair<string, string>[openWith.Count];
        openWith.CopyTo(copy, 0);
    
        // List the contents of the array.
        //
        Console.WriteLine();
        foreach( KeyValuePair<string, string>
 element in copy )
        {
            Console.WriteLine("{0}, {1}", element.Key, element.Value);
        }
    }
}

/* This code example produces the following output:

txt, notepad.exe
bmp, paint.exe
dib, paint.exe
rtf, wordpad.exe

Contains(KeyValuePair("txt", "notepad.exe")): True

Remove(new KeyValuePair("dib", "paint.exe"))

txt, notepad.exe
bmp, paint.exe
rtf, wordpad.exe

txt, notepad.exe
bmp, paint.exe
rtf, wordpad.exe
 */
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



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

辞書ショートカット

すべての辞書の索引

Dictionary.System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>.Remove メソッドのお隣キーワード
検索ランキング

   

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



Dictionary.System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>.Remove メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS