C# ArrayList中的Clear方法

Clear方法用于从ArrayList中删除所有元素,当我们应用Clear方法时,元素的数量变为零,因为它从ArrayList中删除所有元素。

C# ArrayList中的Clear方法示例

namespace ConsoleApplication1
{

  class Program
  {
      static void Main(string[] args)
      {

          ArrayList months = new ArrayList();
          months.Add("march");
          months.Add("april");
          months.Add("may");

          months.Add("june");
          months.Add("july");
          //before apply the clear method
          Console.WriteLine("The elements in the arraylist are:" + months.Count);

          months.Clear();
          Console.WriteLine("After apply the clear method the arraylist is:" + months.Count);
      }
  }

}
日期:2020-04-11 22:50:16 来源:oir作者:oir