Hashtable.Remove メソッドとは? わかりやすく解説

Hashtable.Remove メソッド

指定したキー持つ要素Hashtable から削除します

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

例外例外
例外種類条件

ArgumentNullException

keynull 参照 (Visual Basic では Nothing) です。

NotSupportedException

Hashtable読み取り専用です。

または

Hashtable固定サイズです。

解説解説
使用例使用例

Hashtable から要素削除する方法の例を次に示します

Imports System
Imports System.Collections
Imports Microsoft.VisualBasic

Public Class SamplesHashtable    
    
    Public Shared Sub Main()
        
        ' Creates and initializes a new Hashtable.
        Dim myHT As New
 Hashtable()
        myHT.Add("1a", "The")
        myHT.Add("1b", "quick")
        myHT.Add("1c", "brown")
        myHT.Add("2a", "fox")
        myHT.Add("2b", "jumped")
        myHT.Add("2c", "over")
        myHT.Add("3a", "the")
        myHT.Add("3b", "lazy")
        myHT.Add("3c", "dog")
        
        ' Displays the Hashtable.
        Console.WriteLine("The Hashtable initially contains the
 following:")
        PrintKeysAndValues(myHT)
        
        ' Removes the element with the key "3b".
        myHT.Remove("3b")
        
        ' Displays the current state of the Hashtable.
        Console.WriteLine("After removing ""lazy"":")
        PrintKeysAndValues(myHT)
    End Sub    
    
    
    Public Shared Sub PrintKeysAndValues(myHT
 As Hashtable)
        Dim de As DictionaryEntry
        For Each de In 
 myHT
            Console.WriteLine("    {0}:    {1}", de.Key,
 de.Value)
        Next de
        Console.WriteLine()
    End Sub
End Class


' This code produces the following output.
' 
'The Hashtable initially contains the following:
'    2c:    over
'    3a:    the
'    2b:    jumped
'    3b:    lazy
'    1b:    quick
'    3c:    dog
'    2a:    fox
'    1c:    brown
'    1a:    The
'
'After removing "lazy":
'    2c:    over
'    3a:    the
'    2b:    jumped
'    1b:    quick
'    3c:    dog
'    2a:    fox
'    1c:    brown
'    1a:    The

using System;
using System.Collections;
public class SamplesHashtable  {

   public static void Main()
  {

      // Creates and initializes a new Hashtable.
      Hashtable myHT = new Hashtable();
      myHT.Add( "1a", "The" );
      myHT.Add( "1b", "quick" );
      myHT.Add( "1c", "brown" );
      myHT.Add( "2a", "fox" );
      myHT.Add( "2b", "jumped" );
      myHT.Add( "2c", "over" );
      myHT.Add( "3a", "the" );
      myHT.Add( "3b", "lazy" );
      myHT.Add( "3c", "dog" );

      // Displays the Hashtable.
      Console.WriteLine( "The Hashtable initially contains the following:"
 );
      PrintKeysAndValues( myHT );

      // Removes the element with the key "3b".
      myHT.Remove( "3b" );

      // Displays the current state of the Hashtable.
      Console.WriteLine( "After removing \"lazy\":" );
      PrintKeysAndValues( myHT );
   }


   public static void PrintKeysAndValues(
 Hashtable myHT )  {
      foreach ( DictionaryEntry de in myHT
 )
         Console.WriteLine( "    {0}:    {1}", de.Key, de.Value );
      Console.WriteLine();
   }

}


/*
This code produces the following output.

The Hashtable initially contains the following:
    2c:    over
    3a:    the
    2b:    jumped
    3b:    lazy
    1b:    quick
    3c:    dog
    2a:    fox
    1c:    brown
    1a:    The

After removing "lazy":
    2c:    over
    3a:    the
    2b:    jumped
    1b:    quick
    3c:    dog
    2a:    fox
    1c:    brown
    1a:    The

*/
using namespace System;
using namespace System::Collections;
void PrintKeysAndValues( Hashtable^ myHT );
int main()
{
   
   // Creates and initializes a new Hashtable.
   Hashtable^ myHT = gcnew Hashtable;
   myHT->Add( "1a", "The" );
   myHT->Add( "1b", "quick" );
   myHT->Add( "1c", "brown" );
   myHT->Add( "2a", "fox" );
   myHT->Add( "2b", "jumped" );
   myHT->Add( "2c", "over" );
   myHT->Add( "3a", "the" );
   myHT->Add( "3b", "lazy" );
   myHT->Add( "3c", "dog" );
   
   // Displays the Hashtable.
   Console::WriteLine( "The Hashtable initially contains the following:"
 );
   PrintKeysAndValues( myHT );
   
   // Removes the element with the key "3b".
   myHT->Remove( "3b" );
   
   // Displays the current state of the Hashtable.
   Console::WriteLine( "After removing \"lazy\":" );
   PrintKeysAndValues( myHT );
}

void PrintKeysAndValues( Hashtable^ myHT )
{
   IEnumerator^ myEnum = myHT->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      DictionaryEntry de = *safe_cast<DictionaryEntry ^>(myEnum->Current);
      Console::WriteLine( "    {0}:    {1}", de.Key, de.Value );
   }

   Console::WriteLine();
}

/*
 This code produces the following output.
 
 The Hashtable initially contains the following:
     2c:    over
     3a:    the
     2b:    jumped
     3b:    lazy
     1b:    quick
     3c:    dog
     2a:    fox
     1c:    brown
     1a:    The

 After removing "lazy":
     2c:    over
     3a:    the
     2b:    jumped
     1b:    quick
     3c:    dog
     2a:    fox
     1c:    brown
     1a:    The

 */
import System.*;
import System.Collections.*;

public class SamplesHashtable
{
    public static void main(String[]
 args)
    {
        // Creates and initializes a new Hashtable.
        Hashtable myHT = new Hashtable();

        myHT.Add("1a", "The");
        myHT.Add("1b", "quick");
        myHT.Add("1c", "brown");
        myHT.Add("2a", "fox");
        myHT.Add("2b", "jumped");
        myHT.Add("2c", "over");
        myHT.Add("3a", "the");
        myHT.Add("3b", "lazy");
        myHT.Add("3c", "dog");

        // Displays the Hashtable.
        Console.WriteLine("The Hashtable initially contains the following:");
        PrintKeysAndValues(myHT);

        // Removes the element with the key "3b".
        myHT.Remove("3b");

        // Displays the current state of the Hashtable.
        Console.WriteLine("After removing \"lazy\":");
        PrintKeysAndValues(myHT);
    } //main

    public static void PrintKeysAndValues(Hashtable
 myHT)
    {
        IEnumerator myEnumerator = myHT.GetEnumerator();
        while (myEnumerator.MoveNext()) {
            DictionaryEntry de = (DictionaryEntry)myEnumerator.get_Current();
            Console.WriteLine("    {0}:    {1}", de.get_Key(), de.get_Value());
        }
        Console.WriteLine();
    } //PrintKeysAndValues
} //SamplesHashtable 

/*
 This code produces the following output.
 
 The Hashtable initially contains the following:
     2c:    over
     3a:    the
     2b:    jumped
     3b:    lazy
     1b:    quick
     3c:    dog
     2a:    fox
     1c:    brown
     1a:    The

 After removing "lazy":
     2c:    over
     3a:    the
     2b:    jumped
     1b:    quick
     3c:    dog
     2a:    fox
     1c:    brown
     1a:    The
 */
import System
import System.Collections
import Microsoft.VisualBasic

// Creates and initializes a new Hashtable.
var myHT : Hashtable = new Hashtable()
myHT.Add("1a", "The")
myHT.Add("1b", "quick")
myHT.Add("1c", "brown")
myHT.Add("2a", "fox")
myHT.Add("2b", "jumped")
myHT.Add("2c", "over")
myHT.Add("3a", "the")
myHT.Add("3b", "lazy")
myHT.Add("3c", "dog")

// Displays the Hashtable.
Console.WriteLine("The Hashtable initially contains the following:")
PrintKeysAndValues(myHT)

// Removes the element with the key "3b".
myHT.Remove("3b")

// Displays the current state of the Hashtable.
Console.WriteLine("After removing \"lazy\":")
PrintKeysAndValues(myHT)

function PrintKeysAndValues(myList : Hashtable){
    var myEnumerator : IDictionaryEnumerator = myList.GetEnumerator()
    Console.WriteLine("\t-KEY-\t-VALUE-")
    while(myEnumerator.MoveNext())
        Console.WriteLine("\t{0}:\t{1}", myEnumerator.Key, myEnumerator.Value)
    Console.WriteLine()
}

// This code produces the following output.
// 
// The Hashtable initially contains the following:
//     -KEY-    -VALUE-
//     3a:      the
//     3c:      dog
//     3b:      lazy
//     1c:      brown
//     1b:      quick
//     1a:      The
//     2a:      fox
//     2b:      jumped
//     2c:      over
// 
// After removing "lazy":
//     -KEY-    -VALUE-
//     3a:      the
//     3c:      dog
//     1c:      brown
//     1b:      quick
//     1a:      The
//     2a:      fox
//     2b:      jumped
//     2c:      over 
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からHashtable.Remove メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からHashtable.Remove メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からHashtable.Remove メソッドを検索

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

辞書ショートカット

すべての辞書の索引

「Hashtable.Remove メソッド」の関連用語

Hashtable.Remove メソッドのお隣キーワード
検索ランキング

   

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



Hashtable.Remove メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS