如何在c#实现数据的插入和删除。比如建立一个数组,要讲一任意的数插入在任意的位置,然后输出这个数组,还有就是删除一个任意位置的数,然后也同样输出这个数组。该怎么做啊?希望各位高手帮帮我啊~~~

解决方案 »

  1.   

    用类实现啊:public class Link
    {
        int number;
        Link next;    public Link(int val)
        {
           this.number = val;
           next = null;
        }
        
        //增加链
        public void Add(int val);
         
        //删除链
         public void Remove(int val);
    }
      

  2.   

    用ArrayList
    面的代码示例演示如何创建并初始化 ArrayList 以及如何打印出其值
    using System;
    using System.Collections;
    public class SamplesArrayList  {   public static void Main()  {      // Creates and initializes a new ArrayList.
          ArrayList myAL = new ArrayList();
          myAL.Add("Hello");
          myAL.Add("World");
          myAL.Add("!");      // Displays the properties and values of the ArrayList.
          Console.WriteLine( "myAL" );
          Console.WriteLine( "    Count:    {0}", myAL.Count );
          Console.WriteLine( "    Capacity: {0}", myAL.Capacity );
          Console.Write( "    Values:" );
          PrintValues( myAL );
       }   public static void PrintValues( IEnumerable myList )  {
          foreach ( Object obj in myList )
             Console.Write( "   {0}", obj );
          Console.WriteLine();
       }}
    /* 
    This code produces output similar to the following:myAL
        Count:    3
        Capacity: f
        Values:   Hello   World   !*/