SortedList.Remove メソッド
アセンブリ: System (system.dll 内)

Dim instance As SortedList(Of TKey, TValue) Dim key As TKey Dim returnValue As Boolean returnValue = instance.Remove(key)
戻り値
要素が正常に削除された場合は true。それ以外の場合は false。このメソッドは、key が元の SortedList に見つからなかった場合にも false を返します。



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

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


SortedList.Remove メソッド
アセンブリ: mscorlib (mscorlib.dll 内)



指定したキーを持つ要素が 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 */

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からSortedList.Removeを検索する場合は、下記のリンクをクリックしてください。

- SortedList.Removeのページへのリンク