获取特定项目的数组索引 [英] Getting the index of a particular item in array

查看:104
本文介绍了获取特定项目的数组索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检索数组的索引,但我知道只有数组比如我是阵列中存储作者姓名实际价值的一部分动态地说:作者='某某'
我想找到包含像笔者数组元素的索引,因为我不知道这个值部分如何做到这一点。

i want to retrieve the index of an array but i know only a part of the actual value in the array for example i am storing author name in the array dynamically say "author = 'xyz' " i want to find the index of array item containing something like author as i don't know the value part how to do this.

推荐答案

您可以使用的 FindIndex

 var index = Array.FindIndex(myArray, row => row.Author == "xyz");

编辑:我看你有没有字符串数组,你可以使用任何code相匹配,这里的例子用一个简单的包含:

I see you have an array of string, you can use any code to match, here an example with a simple contains:

 var index = Array.FindIndex(myArray, row => row.Contains("Author='xyz'"));

也许你需要使用定期EX $ P匹配$ pssion

这篇关于获取特定项目的数组索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆