要从sortedlist的指定索引中删除,代码如下-
using system; using system.collections; public class demo { public static void main(string[] args) { sortedlist sortedlist = new sortedlist(); sortedlist.add("a", "1"); sortedlist.add("b", "2"); sortedlist.add("c", "3"); sortedlist.add("d", "4"); sortedlist.add("e", "5"); sortedlist.add("f", "6"); sortedlist.add("g", "7"); sortedlist.add("h", "8"); sortedlist.add("i", "9"); sortedlist.add("j", "10"); console.writeline("sortedlist elements..."); foreach(dictionaryentry d in sortedlist) { console.writeline("key = " d.key ", value = " d.value); } console.writeline("count of sortedlist key-value pairs = " sortedlist.count); sortedlist.removeat(3); console.writeline("\nenumerator to iterate through the sortedlist..."); idictionaryenumerator demoenum = sortedlist.getenumerator(); while (demoenum.movenext()) console.writeline("key = " demoenum.key ", value = " demoenum.value); console.writeline("count of sortedlist key-value pairs (updated) = " sortedlist.count); } }
输出结果
这将产生以下输出-
sortedlist elements... key = a, value = 1 key = b, value = 2 key = c, value = 3 key = d, value = 4 key = e, value = 5 key = f, value = 6 key = g, value = 7 key = h, value = 8 key = i, value = 9 key = j, value = 10 count of sortedlist key-value pairs = 10 enumerator to iterate through the sortedlist... key = a, value = 1 key = b, value = 2 key = c, value = 3 key = e, value = 5 key = f, value = 6 key = g, value = 7 key = h, value = 8 key = i, value = 9 key = j, value = 10 count of sortedlist key-value pairs (updated) = 9
让我们看另一个例子-
using system; using system.collections; public class demo { public static void main(string[] args) { sortedlist sortedlist = new sortedlist(); sortedlist.add("one", "mouse"); sortedlist.add("two", "keyboard"); sortedlist.add("three", "headphone"); sortedlist.add("four", "speakers"); sortedlist.add("five", "ram"); console.writeline("sortedlist elements..."); foreach(dictionaryentry d in sortedlist) { console.writeline("key = " d.key ", value = " d.value); } console.writeline("count of sortedlist key-value pairs = " sortedlist.count); sortedlist.removeat(1); sortedlist.removeat(2); console.writeline("\nenumerator to iterate through the sortedlist..."); idictionaryenumerator demoenum = sortedlist.getenumerator(); while (demoenum.movenext()) console.writeline("key = " demoenum.key ", value = " demoenum.value); console.writeline("count of sortedlist key-value pairs (updated) = " sortedlist.count); } }
输出结果
这将产生以下输出-
sortedlist elements... key = five, value = ram key = four, value = speakers key = one, value = mouse key = three, value = headphone key = two, value = keyboard count of sortedlist key-value pairs = 5 enumerator to iterate through the sortedlist... key = five, value = ram key = one, value = mouse key = two, value = keyboard count of sortedlist key-value pairs (updated) = 3
888棋牌游戏的友情链接: