C# ArrayList中的indexof方法示例

namespace ConsoleApplication1
{

  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"));
          Console.WriteLine("The index value of Orange is:" + arr.IndexOf("Orange"));
          Console.WriteLine("The index value of White is:" + arr.IndexOf("White"));

          Console.WriteLine("The index value of Blue is:" + arr.IndexOf("Blue"));
      }
  }
}
C# ArrayList中的indexof方法

indexOf(Object)方法搜索指定的对象,并返回整个ArrayList内的第一个匹配对象的索引。

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