获取数组中特定项的索引 [英] Getting the index of a particular item in array
本文介绍了获取数组中特定项的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检索数组的索引,但我只知道数组中实际值的一部分.
I want to retrieve the index of an array but I know only a part of the actual value in the array.
例如,我在数组中动态存储作者姓名,例如author = 'xyz'".
现在我想找到包含它的数组项的索引,因为我不知道值部分.
For example, I am storing an author name in the array dynamically say "author = 'xyz'".
Now I want to find the index of the array item containing it, since I don't know the value part.
如何做到这一点?
推荐答案
您可以使用 查找索引
var index = Array.FindIndex(myArray, row => row.Author == "xyz");
我看到你有一个字符串数组,你可以使用任何代码来匹配,这里有一个简单的例子:
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'"));
也许您需要使用正则表达式进行匹配?
这篇关于获取数组中特定项的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文