在列表中查找int的索引
有没有办法从列表中获取int的索引? 寻找类似list1.FindIndex(5)
东西,我想在列表中找到5的位置。
使用列表的.IndexOf()
方法。 该方法的规范可以在MSDN上找到。
FindIndex似乎是您正在寻找的:
FindIndex(Predicate
用法:
list1.FindIndex(x => x==5);
例:
// given list1 {3, 4, 6, 5, 7, 8} list1.FindIndex(x => x==5); // should return 3, as list1[3] == 5;
试试IndexOf 。
List accountList = new List {"123872", "987653" , "7625019", "028401"}; int i = accountList.FindIndex(x => x.StartsWith("762")); //This will give you index of 7625019 in list that is 2. value of i will become 2. //delegate(string ac) //{ // return ac.StartsWith(a.AccountNumber); //} //);
- Ploeh AutoFixture无法从System.Runtime.Serialization.ExtensionDataObject创建实例
- 使用c#解析XML数据
- 将平面JSON / Dictionary映射到模型(包含子类)
- 加密C#中web.config文件中的连接字符串
- 将Asp.net MVC模型数据绑定到kendo TreeView模板(本地数据)
- c#:ExecuteNonQuery()返回-1
- 在Entity Framework支持的Web API 2 POST调用中返回一个对象以及409 Conflict错误?
- 将字符串解析为int数组
- 使用C#连接到SQL Server 2012数据库(Visual Studio 2012)