zoukankan      html  css  js  c++  java
  • 【转载】C#的ArrayList使用IndexOf方法查找第一个符合条件的元素位置

    在C#的编程开发中,ArrayList集合是一个常用的非泛型类集合,在ArrayList集合中如果需要查找第一个符合条件的元素所在的位置,可以使用ArrayList集合的IndexOf方法,IndexOf方法将会返回符合条件的第一个元素在集合中的索引位置信息,如果未查到符合条件的元素对象,则返回-1。

    IndexOf方法的其中一个常用方法签名为:virtual int IndexOf(object value),value代表需要查找匹配的对象数据。

    例如,有个ArrayList集合存储的数据都为Int类型,需要查找数字10第一次出现在ArrayList集合中的位置,可使用下列语句:

       ArrayList arrayList1 = new ArrayList();
       arrayList1.Add(1);
       arrayList1.Add(2);
       arrayList1.Add(10);
       arrayList1.Add(3);
    
       int index10 = arrayList1.IndexOf(10);//返回index10=2

    上述程序执行结果为,index10=2。即数字10第一次出现在arrayList1集合中的索引为2。

  • 相关阅读:
    SpringMVC + MyBatis简单示例
    JSP---JSTL核心标签库的使用
    HBASE安装 (HA)
    HBase 常用Shell命令(转载)
    kafka quick start
    在IDEA中实战Git
    kibana6.2.2安装
    elasticsearch-head插件安装
    elasticsearch6.2.2安装
    jdk1.8安装
  • 原文地址:https://www.cnblogs.com/xu-yi/p/11254968.html
Copyright © 2011-2022 走看看