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

SortedList.Remove メソッド

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

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

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

例外例外
例外種類条件

ArgumentNullException

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

解説解説

このメソッドは、バイナリ サーチ実行しますが、空いている位置埋めるために要素位置上がるため、このメソッドは O(n) 操作です。ここで、n は、Count です。

使用例使用例

Remove メソッド使用してキー/値ペア並べ替えられたリストから削除する方法次のコード例示します

このコード例は、SortedList クラストピック取り上げているコード例一部分です。

' Use the Remove method to remove a key/value pair.
Console.WriteLine(vbLf + "Remove(""doc"")")
openWith.Remove("doc")

If Not openWith.ContainsKey("doc")
 Then
    Console.WriteLine("Key ""doc""
 is not found.")
End If
// Use the Remove method to remove a key/value pair.
Console.WriteLine("\nRemove(\"doc\")");
openWith.Remove("doc");

if (!openWith.ContainsKey("doc"))
{
    Console.WriteLine("Key \"doc\" is not found.");
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
SortedList ジェネリック クラス
SortedList メンバ
System.Collections.Generic 名前空間
RemoveAt
SortedList.Clear メソッド
SortedList.Add メソッド

SortedList.Remove メソッド

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

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

例外例外
例外種類条件

ArgumentNullException

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

NotSupportedException

SortedList読み取り専用です。

または

SortedList固定サイズです。

解説解説
使用例使用例

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

Imports System
Imports System.Collections
Imports Microsoft.VisualBasic

Public Class SamplesSortedList    
    
    Public Shared Sub Main()
        
        ' Creates and initializes a new SortedList.
        Dim mySL As New
 SortedList()
        mySL.Add("3c", "dog")
        mySL.Add("2c", "over")
        mySL.Add("1c", "brown")
        mySL.Add("1a", "The")
        mySL.Add("1b", "quick")
        mySL.Add("3a", "the")
        mySL.Add("3b", "lazy")
        mySL.Add("2a", "fox")
        mySL.Add("2b", "jumped")
        
        ' Displays the SortedList.
        Console.WriteLine("The SortedList initially contains the
 following:")
        PrintKeysAndValues(mySL)
        
        ' Removes the element with the key "3b".
        mySL.Remove("3b")
        
        ' Displays the current state of the SortedList.
        Console.WriteLine("After removing ""lazy"":")
        PrintKeysAndValues(mySL)
        
        ' Removes the element at index 5.
        mySL.RemoveAt(5)
        
        ' Displays the current state of the SortedList.
        Console.WriteLine("After removing the element at index
 5:")
        PrintKeysAndValues(mySL)
    End Sub
    
    
    Public Shared Sub PrintKeysAndValues(myList
 As SortedList)
        Console.WriteLine(ControlChars.Tab & "-KEY-"
 & ControlChars.Tab & _
           "-VALUE-")
        Dim i As Integer
        For i = 0 To myList.Count - 1
            Console.WriteLine(ControlChars.Tab & "{0}:"
 & ControlChars.Tab & _
               "{1}", myList.GetKey(i), myList.GetByIndex(i))
        Next i
        Console.WriteLine()
    End Sub
End Class

' This code produces the following output.
' 
' The SortedList initially contains the following:
'     -KEY-    -VALUE-
'     1a:    The
'     1b:    quick
'     1c:    brown
'     2a:    fox
'     2b:    jumped
'     2c:    over
'     3a:    the
'     3b:    lazy
'     3c:    dog
' 
' After removing "lazy":
'     -KEY-    -VALUE-
'     1a:    The
'     1b:    quick
'     1c:    brown
'     2a:    fox
'     2b:    jumped
'     2c:    over
'     3a:    the
'     3c:    dog
' 
' After removing the element at index 5:
'     -KEY-    -VALUE-
'     1a:    The
'     1b:    quick
'     1c:    brown
'     2a:    fox
'     2b:    jumped
'     3a:    the
'     3c:    dog 
using System;
using System.Collections;
public class SamplesSortedList  {

   public static void Main()
  {

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

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

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

      // Displays the current state of the SortedList.
      Console.WriteLine( "After removing \"lazy\":" );
      PrintKeysAndValues( mySL );

      // Removes the element at index 5.
      mySL.RemoveAt( 5 );

      // Displays the current state of the SortedList.
      Console.WriteLine( "After removing the element at index 5:" );
      PrintKeysAndValues( mySL );
   }


   public static void PrintKeysAndValues(
 SortedList myList )  {
      Console.WriteLine( "\t-KEY-\t-VALUE-" );
      for ( int i = 0; i < myList.Count;
 i++ )  {
         Console.WriteLine( "\t{0}:\t{1}", myList.GetKey(i), myList.GetByIndex(i)
 );
      }
      Console.WriteLine();
   }
}
/* 
This code produces the following output.

The SortedList initially contains the following:
    -KEY-    -VALUE-
    1a:    The
    1b:    quick
    1c:    brown
    2a:    fox
    2b:    jumped
    2c:    over
    3a:    the
    3b:    lazy
    3c:    dog

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

After removing the element at index 5:
    -KEY-    -VALUE-
    1a:    The
    1b:    quick
    1c:    brown
    2a:    fox
    2b:    jumped
    3a:    the
    3c:    dog
*/
#using <system.dll>

using namespace System;
using namespace System::Collections;
void PrintKeysAndValues( SortedList^ myList )
{
   Console::WriteLine( "\t-KEY-\t-VALUE-" );
   for ( int i = 0; i < myList->Count;
 i++ )
   {
      Console::WriteLine( "\t{0}:\t{1}", myList->GetKey( i ), myList->GetByIndex(
 i ) );

   }
   Console::WriteLine();
}

int main()
{
   
   // Creates and initializes a new SortedList.
   SortedList^ mySL = gcnew SortedList;
   mySL->Add( "3c", "dog" );
   mySL->Add( "2c", "over" );
   mySL->Add( "1c", "brown" );
   mySL->Add( "1a", "The" );
   mySL->Add( "1b", "quick" );
   mySL->Add( "3a", "the" );
   mySL->Add( "3b", "lazy" );
   mySL->Add( "2a", "fox" );
   mySL->Add( "2b", "jumped" );
   
   // Displays the SortedList.
   Console::WriteLine( "The SortedList initially contains the following:"
 );
   PrintKeysAndValues( mySL );
   
   // Removes the element with the key "3b".
   mySL->Remove( "3b" );
   
   // Displays the current state of the SortedList.
   Console::WriteLine( "After removing \"lazy\":" );
   PrintKeysAndValues( mySL );
   
   // Removes the element at index 5.
   mySL->RemoveAt( 5 );
   
   // Displays the current state of the SortedList.
   Console::WriteLine( "After removing the element at index 5:" );
   PrintKeysAndValues( mySL );
}

/*
This code produces the following output.

The SortedList initially contains the following:
        -KEY-   -VALUE-
        1a:     The
        1b:     quick
        1c:     brown
        2a:     fox
        2b:     jumped
        2c:     over
        3a:     the
        3b:     lazy
        3c:     dog

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

After removing the element at index 5:
        -KEY-   -VALUE-
        1a:     The
        1b:     quick
        1c:     brown
        2a:     fox
        2b:     jumped
        3a:     the
        3c:     dog
*/
import System.*;
import System.Collections.*;

public class SamplesSortedList
{
    public static void main(String[]
 args)
    {
        // Creates and initializes a new SortedList.
        SortedList mySL = new SortedList();

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

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

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

        // Displays the current state of the SortedList.
        Console.WriteLine("After removing \"lazy\":");
        PrintKeysAndValues(mySL);

        // Removes the element at index 5.
        mySL.RemoveAt(5);

        // Displays the current state of the SortedList.
        Console.WriteLine("After removing the element at index 5:");
        PrintKeysAndValues(mySL);
    } //main

    public static void PrintKeysAndValues(SortedList
 myList)
    {
        Console.WriteLine("\t-KEY-\t-VALUE-");
        for (int i = 0; i < myList.get_Count();
 i++) {
            Console.WriteLine("\t{0}:\t{1}", myList.GetKey(i), 
                myList.GetByIndex(i));
        }
        Console.WriteLine();
    } //PrintKeysAndValues

} //SamplesSortedList
/* 
 This code produces the following output.
 
 The SortedList initially contains the following:
        -KEY-   -VALUE-
        1a:     The
        1b:     quick
        1c:     brown
        2a:     fox
        2b:     jumped
        2c:     over
        3a:     the
        3b:     lazy
        3c:     dog

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

 After removing the element at index 5:
        -KEY-   -VALUE-
        1a:     The
        1b:     quick
        1c:     brown
        2a:     fox
        2b:     jumped
        3a:     the
        3c:     dog
 */
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



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

辞書ショートカット

すべての辞書の索引

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

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

   

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



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

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

©2024 GRAS Group, Inc.RSS