Dictionary<TKey,TValue>.IDictionary.Remove(Object) 메서드

정의

IDictionary에서 지정한 키를 가지는 요소를 제거합니다.

 virtual void System.Collections.IDictionary.Remove(System::Object ^ key) = System::Collections::IDictionary::Remove;
void IDictionary.Remove (object key);
abstract member System.Collections.IDictionary.Remove : obj -> unit
override this.System.Collections.IDictionary.Remove : obj -> unit
Sub Remove (key As Object) Implements IDictionary.Remove

매개 변수

key
Object

제거할 요소의 키입니다.

구현

예외

key이(가) null인 경우

예제

다음 코드 예제를 사용 IDictionary.Remove 하는 방법을 보여 입니다 의 System.Collections.IDictionary 인터페이스를 사용 하 여 합니다 Dictionary<TKey,TValue>.

코드 예제는 메서드에 제공된 출력을 포함하여 더 큰 예제의 IDictionary.Add 일부입니다.

using System;
using System.Collections;
using System.Collections.Generic;

public class Example
{
    public static void Main()
    {
        // Create a new dictionary of strings, with string keys,
        // and access it using the IDictionary interface.
        //
        IDictionary openWith = new Dictionary<string, string>();

        // Add some elements to the dictionary. There are no
        // duplicate keys, but some of the values are duplicates.
        // IDictionary.Add throws an exception if incorrect types
        // are supplied for key or value.
        openWith.Add("txt", "notepad.exe");
        openWith.Add("bmp", "paint.exe");
        openWith.Add("dib", "paint.exe");
        openWith.Add("rtf", "wordpad.exe");
Imports System.Collections
Imports System.Collections.Generic

Public Class Example
    
    Public Shared Sub Main() 

        ' Create a new dictionary of strings, with string keys,
        ' and access it using the IDictionary interface.
        '
        Dim openWith As IDictionary = _
            New Dictionary(Of String, String)
        
        ' Add some elements to the dictionary. There are no 
        ' duplicate keys, but some of the values are duplicates.
        ' IDictionary.Add throws an exception if incorrect types
        ' are supplied for key or value.
        openWith.Add("txt", "notepad.exe")
        openWith.Add("bmp", "paint.exe")
        openWith.Add("dib", "paint.exe")
        openWith.Add("rtf", "wordpad.exe")
// Use the Remove method to remove a key/value pair. No
// exception is thrown if the wrong data type is supplied.
Console.WriteLine("\nRemove(\"dib\")");
openWith.Remove("dib");

if (!openWith.Contains("dib"))
{
    Console.WriteLine("Key \"dib\" is not found.");
}
' Use the Remove method to remove a key/value pair. No
' exception is thrown if the wrong data type is supplied.
Console.WriteLine(vbLf + "Remove(""dib"")")
openWith.Remove("dib")

If Not openWith.Contains("dib") Then
    Console.WriteLine("Key ""dib"" is not found.")
End If
    }
}

    End Sub

End Class

설명

이 메서드는 O(1) 작업에 접근합니다.

적용 대상