本文整理汇总了C#中System.Collections.SortedList.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# SortedList.Remove方法的具体用法?C# SortedList.Remove怎么用?C# SortedList.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.SortedList
的用法示例。
在下文中一共展示了SortedList.Remove方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
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", "jumps" );
// 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();
}
}
输出:
The SortedList initially contains the following: -KEY- -VALUE- 1a: The 1b: quick 1c: brown 2a: fox 2b: jumps 2c: over 3a: the 3b: lazy 3c: dog After removing "lazy": -KEY- -VALUE- 1a: The 1b: quick 1c: brown 2a: fox 2b: jumps 2c: over 3a: the 3c: dog After removing the element at index 5: -KEY- -VALUE- 1a: The 1b: quick 1c: brown 2a: fox 2b: jumps 3a: the 3c: dog
示例2: Main
//引入命名空间
using System;
using System.Collections;
public class MainClass {
public static void Main() {
SortedList list = new SortedList();
list.Add("G", "B");
list.Add("Ae", "Sm");
list.Add("Ay", "G");
list.Add("Ab", "S");
list.Add("W", "C");
list.Remove("Abraxus");
list.RemoveAt(2);
String artist = (string)list["Ay"];
Console.WriteLine(artist);
String error = (string)list["S"];
Console.WriteLine(error);
foreach (DictionaryEntry d in list) {
Console.WriteLine("{0}, {1}", d.Key, d.Value);
}
}
}