当前位置: 首页>>代码示例>>C#>>正文


C# SortedList.RemoveAt方法代码示例

本文整理汇总了C#中System.Collections.SortedList.RemoveAt方法的典型用法代码示例。如果您正苦于以下问题:C# SortedList.RemoveAt方法的具体用法?C# SortedList.RemoveAt怎么用?C# SortedList.RemoveAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Collections.SortedList的用法示例。


在下文中一共展示了SortedList.RemoveAt方法的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();
   }
}
开发者ID:.NET开发者,项目名称:System.Collections,代码行数:46,代码来源:SortedList.RemoveAt

输出:

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);
        }
    }
}
开发者ID:C#程序员,项目名称:System.Collections,代码行数:28,代码来源:SortedList.RemoveAt


注:本文中的System.Collections.SortedList.RemoveAt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。