다음을 통해 공유


IDictionary.Remove 메서드

IDictionary 개체에서 지정된 키가 있는 요소를 제거합니다.

네임스페이스: System.Collections
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
Sub Remove ( _
    key As Object _
)
‘사용 방법
Dim instance As IDictionary
Dim key As Object

instance.Remove(key)
void Remove (
    Object key
)
void Remove (
    Object^ key
)
void Remove (
    Object key
)
function Remove (
    key : Object
)

매개 변수

  • key
    제거할 요소의 키입니다.

예외

예외 형식 조건

ArgumentNullException

key가 Null 참조(Visual Basic의 경우 Nothing)인 경우

NotSupportedException

IDictionary 개체가 읽기 전용인 경우

- 또는 -

IDictionary의 크기가 고정되어 있는 경우

설명

IDictionary 개체에 지정된 키를 갖는 요소가 없으면 IDictionary는 변경되지 않은 상태로 유지됩니다. 예외가 throw되지 않습니다.

예제

다음 코드 예제에서는 Remove 메서드를 구현하는 방법을 보여 줍니다. 이 코드 예제는 IDictionary 클래스에 대해 제공되는 보다 큰 예제의 일부입니다.

Public Sub Remove(ByVal key As Object) Implements IDictionary.Remove
    If key = Nothing Then
        Throw New ArgumentNullException("key")
    End If
    ' Try to find the key in the DictionaryEntry array
    Dim index As Integer
    If TryGetIndexOfKey(key, index) Then

        ' If the key is found, slide all the items up.
        Array.Copy(items, index + 1, items, index, (ItemsInUse - index) - 1)
        ItemsInUse = ItemsInUse - 1
    Else

        ' If the key is not in the dictionary, just return. 
    End If
End Sub
public void Remove(object key)
{
    if (key == null) throw new ArgumentNullException("key");
    // Try to find the key in the DictionaryEntry array
    Int32 index;
    if (TryGetIndexOfKey(key, out index))
    {
        // If the key is found, slide all the items up.
        Array.Copy(items, index + 1, items, index, ItemsInUse - index - 1);
        ItemsInUse--;
    } 
    else
    {
        // If the key is not in the dictionary, just return. 
    }
}
public:
    virtual void Remove(Object^ key)
    {
        if (key == nullptr)
        {
            throw gcnew ArgumentNullException("key");
        }
        // Try to find the key in the DictionaryEntry array
        int index;
        if (TryGetIndexOfKey(key, &index))
        {
            // If the key is found, slide all the items down.
            Array::Copy(items, index + 1, items, index, itemsInUse -
                index - 1);
            itemsInUse--;
        }
        else
        {
            // If the key is not in the dictionary, just return.
            return;
        }
    }

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

IDictionary 인터페이스
IDictionary 멤버
System.Collections 네임스페이스