ListDictionary.Remove メソッド
指定したキーを持つエントリを ListDictionary から削除します。
Public Overridable Sub Remove( _
ByVal key As Object _) Implements IDictionary.Remove
[C#]
public virtual void Remove(objectkey);
[C++]
public: virtual void Remove(Object* key);
[JScript]
public function Remove(
key : Object);
パラメータ
- key
削除するエントリのキー。
実装
例外
例外の種類 | 条件 |
---|---|
ArgumentNullException | key が null 参照 (Visual Basic では Nothing) です。 |
解説
指定したキーを持つ要素が ListDictionary に格納されていない場合、 ListDictionary は変更されません。例外はスローされません。
これは O(n) 操作です。 n は Count です。
使用例
[Visual Basic, C#, C++] ListDictionary に対して要素を追加および削除するコード例を次に示します。
Imports System
Imports System.Collections
Imports System.Collections.Specialized
Public Class SamplesListDictionary
Public Shared Sub Main()
' Creates and initializes a new ListDictionary.
Dim myCol As New ListDictionary()
myCol.Add("Braeburn Apples", "1.49")
myCol.Add("Fuji Apples", "1.29")
myCol.Add("Gala Apples", "1.49")
myCol.Add("Golden Delicious Apples", "1.29")
myCol.Add("Granny Smith Apples", "0.89")
myCol.Add("Red Delicious Apples", "0.99")
' Displays the values in the ListDictionary in three different ways.
Console.WriteLine("Initial contents of the ListDictionary:")
PrintKeysAndValues(myCol)
' Deletes a key.
myCol.Remove("Plums")
Console.WriteLine("The collection contains the following elements after removing ""Plums"":")
PrintKeysAndValues(myCol)
' Clears the entire collection.
myCol.Clear()
Console.WriteLine("The collection contains the following elements after it is cleared:")
PrintKeysAndValues(myCol)
End Sub 'Main
Public Shared Sub PrintKeysAndValues(myCol As IDictionary)
Console.WriteLine(" KEY VALUE")
Dim de As DictionaryEntry
For Each de In myCol
Console.WriteLine(" {0,-25} {1}", de.Key, de.Value)
Next de
Console.WriteLine()
End Sub 'PrintKeysAndValues
End Class 'SamplesListDictionary
'This code produces the following output.
'
'Initial contents of the ListDictionary:
' KEY VALUE
' Braeburn Apples 1.49
' Fuji Apples 1.29
' Gala Apples 1.49
' Golden Delicious Apples 1.29
' Granny Smith Apples 0.89
' Red Delicious Apples 0.99
'
'The collection contains the following elements after removing "Plums":
' KEY VALUE
' Braeburn Apples 1.49
' Fuji Apples 1.29
' Gala Apples 1.49
' Golden Delicious Apples 1.29
' Granny Smith Apples 0.89
' Red Delicious Apples 0.99
'
'The collection contains the following elements after it is cleared:
' KEY VALUE
'
[C#]
using System;
using System.Collections;
using System.Collections.Specialized;
public class SamplesListDictionary {
public static void Main() {
// Creates and initializes a new ListDictionary.
ListDictionary myCol = new ListDictionary();
myCol.Add( "Braeburn Apples", "1.49" );
myCol.Add( "Fuji Apples", "1.29" );
myCol.Add( "Gala Apples", "1.49" );
myCol.Add( "Golden Delicious Apples", "1.29" );
myCol.Add( "Granny Smith Apples", "0.89" );
myCol.Add( "Red Delicious Apples", "0.99" );
// Displays the values in the ListDictionary in three different ways.
Console.WriteLine( "Initial contents of the ListDictionary:" );
PrintKeysAndValues( myCol );
// Deletes a key.
myCol.Remove( "Plums" );
Console.WriteLine( "The collection contains the following elements after removing \"Plums\":" );
PrintKeysAndValues( myCol );
// Clears the entire collection.
myCol.Clear();
Console.WriteLine( "The collection contains the following elements after it is cleared:" );
PrintKeysAndValues( myCol );
}
public static void PrintKeysAndValues( IDictionary myCol ) {
Console.WriteLine( " KEY VALUE" );
foreach ( DictionaryEntry de in myCol )
Console.WriteLine( " {0,-25} {1}", de.Key, de.Value );
Console.WriteLine();
}
}
/*
This code produces the following output.
Initial contents of the ListDictionary:
KEY VALUE
Braeburn Apples 1.49
Fuji Apples 1.29
Gala Apples 1.49
Golden Delicious Apples 1.29
Granny Smith Apples 0.89
Red Delicious Apples 0.99
The collection contains the following elements after removing "Plums":
KEY VALUE
Braeburn Apples 1.49
Fuji Apples 1.29
Gala Apples 1.49
Golden Delicious Apples 1.29
Granny Smith Apples 0.89
Red Delicious Apples 0.99
The collection contains the following elements after it is cleared:
KEY VALUE
*/
[C++]
#using <mscorlib.dll>
#using <System.dll>
using namespace System;
using namespace System::Collections;
using namespace System::Collections::Specialized;
void PrintKeysAndValues( IDictionary* myCol ) {
Console::WriteLine( S" KEY VALUE" );
IEnumerator* myEnum = myCol->GetEnumerator();
while (myEnum->MoveNext())
{
DictionaryEntry de = *__try_cast<DictionaryEntry*>(myEnum->Current);
Console::WriteLine( S" {0,-25} {1}", de.Key, de.Value );
}
Console::WriteLine();
}
int main() {
// Creates and initializes a new ListDictionary.
ListDictionary* myCol = new ListDictionary();
myCol->Add( S"Braeburn Apples", S"1.49" );
myCol->Add( S"Fuji Apples", S"1.29" );
myCol->Add( S"Gala Apples", S"1.49" );
myCol->Add( S"Golden Delicious Apples", S"1.29" );
myCol->Add( S"Granny Smith Apples", S"0.89" );
myCol->Add( S"Red Delicious Apples", S"0.99" );
// Displays the values in the ListDictionary in three different ways.
Console::WriteLine( S"Initial contents of the ListDictionary:" );
PrintKeysAndValues( myCol );
// Deletes a key.
myCol->Remove( S"Plums" );
Console::WriteLine( S"The collection contains the following elements after removing \"Plums\":" );
PrintKeysAndValues( myCol );
// Clears the entire collection.
myCol->Clear();
Console::WriteLine( S"The collection contains the following elements after it is cleared:" );
PrintKeysAndValues( myCol );
}
/*
This code produces the following output.
Initial contents of the ListDictionary:
KEY VALUE
Braeburn Apples 1.49
Fuji Apples 1.29
Gala Apples 1.49
Golden Delicious Apples 1.29
Granny Smith Apples 0.89
Red Delicious Apples 0.99
The collection contains the following elements after removing "Plums":
KEY VALUE
Braeburn Apples 1.49
Fuji Apples 1.29
Gala Apples 1.49
Golden Delicious Apples 1.29
Granny Smith Apples 0.89
Red Delicious Apples 0.99
The collection contains the following elements after it is cleared:
KEY VALUE
*/
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET
参照
ListDictionary クラス | ListDictionary メンバ | System.Collections.Specialized 名前空間 | Add | IDictionary.Remove | カルチャを認識しない文字列操作の実行