C# ArrayList中的indexof(Object,int32,int32)方法

IndexOf(Object,Int32,Int32)方法搜索指定的对象,并返回ArrayList中元素范围内第一次出现的索引,该范围从指定的索引开始,包含指定数量的元素。

C# ArrayList中的indexof(Object,int32,int32)方法示例

namespace ConsoleApplication3
{

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

          ArrayList arr = new ArrayList();
          arr.Add("Red");
          arr.Add("Pink");
          arr.Add("Orange");

          arr.Add("Yellow");
          arr.Add("Blue");
          arr.Add("Gray");
          arr.Add("White");

          Console.WriteLine("The elements in the arraylist are:");
          foreach (object obj in arr)
          {
              Console.WriteLine(obj);

          }
          Console.WriteLine("The index value of Red is:" + arr.IndexOf("Red", 0, 3));
          Console.WriteLine("The index value of Orange is:" + arr.IndexOf("Orange", 1, 4));
          Console.WriteLine("The index value of Blue is:" + arr.IndexOf("Blue", 2,5));

      }
  }
}
日期:2020-04-11 23:03:40 来源:oir作者:oir