SortedList.RemoveAtとは? わかりやすく解説

SortedList.RemoveAt メソッド

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

SortedList の指定したインデックスにある要素削除します

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

Public Sub RemoveAt ( _
    index As Integer _
)
Dim instance As SortedList(Of
 TKey, TValue)
Dim index As Integer

instance.RemoveAt(index)
public void RemoveAt (
    int index
)
public:
void RemoveAt (
    int index
)
public void RemoveAt (
    int index
)

パラメータ

index

削除する要素の、0 から始まるインデックス番号

例外例外
例外種類条件

ArgumentOutOfRangeException

index が 0 未満です。

または

indexCount上です。

解説解説

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

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
SortedList ジェネリック クラス
SortedList メンバ
System.Collections.Generic 名前空間
SortedList.Remove メソッド
SortedList.Clear メソッド
SortedList.Add メソッド

SortedList.RemoveAt メソッド

SortedList の指定したインデックスにある要素削除します

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

Public Overridable Sub RemoveAt
 ( _
    index As Integer _
)
Dim instance As SortedList
Dim index As Integer

instance.RemoveAt(index)
public virtual void RemoveAt (
    int index
)
public:
virtual void RemoveAt (
    int index
)
public void RemoveAt (
    int index
)

パラメータ

index

削除する要素の、0 から始まるインデックス番号

例外例外
例外種類条件

ArgumentOutOfRangeException

index が、SortedList有効なインデックス範囲外です。

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
 */
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


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

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

辞書ショートカット

すべての辞書の索引

「SortedList.RemoveAt」の関連用語

SortedList.RemoveAtのお隣キーワード
検索ランキング

   

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



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

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

©2024 GRAS Group, Inc.RSS