ArrayList的Insert方法

using System;
using System.Collections;
using System.Text;

namespace myTest
{
    class Program
    {
        static void Main(string[] args)
        {
            MyClass myClass = new MyClass();
            myClass.MyMethod();

            Console.ReadLine();
        }
    }

    class MyClass
    {
        public MyClass()
        {
            Console.WriteLine("测试类。");
        }
        public void MyMethod()
        {
            ArrayList myArrayList = new ArrayList(3);
            myArrayList.Add("Hello");
            myArrayList.Add("World!");

            myArrayList.Insert(1, "Jack ");
            myArrayList.Insert(2, "This is the ");

            Console.WriteLine("Capacity: {0}", myArrayList.Capacity);

            Console.WriteLine("Count: {0}", myArrayList.Count);

            Console.WriteLine(myArrayList[0]);
            Console.WriteLine(myArrayList[1]);
            Console.WriteLine(myArrayList[2]);
            Console.WriteLine(myArrayList[3]);
        }
    }
}

//测试结果
//测试类。
//Capacity: 6
//Count: 4
//Hello
//Jack
//This is the
//World!

原文地址:https://www.cnblogs.com/marslin/p/3058717.html