目录索引搜索 [英] List Index Search
本文介绍了目录索引搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个项目
列表<串GT; xmlValue =新的List<串GT;();
在此我有项目 {英语,西班牙,法国,印地文,英语,英语}
我需要搜索所有的英语项目,其指数(项目索引)沿
。
我写了下面的代码返回指数只有1项。如何可以得到下一个项目也索引。
字符串搜索=英语;
INT指数= xmlValue.Select((项目,I)=>新建项目{=项指数= I})
。首先(X => x.Item ==搜索)的.index ;
解决方案
列表<字符串> xmlValue =新的List<串GT;()
{英语,西班牙,法国,印地文,英语,英语};
字符串搜索=英语;
INT []结果= xmlValue.Select((B,I)=> b.Equals(搜索)I:-1?)
。凡(ⅰ= I标记! = -1).ToArray();
I have a List item
List<string> xmlValue = new List<string>();
In this I have Item {"English","Spanish","French","Hindi","English","English"}
I need to search all English item along with its Index(item index)
.
I wrote the below code it returns index only for 1 item .How can get the index for the next item also.
string search = "English";
int index = xmlValue.Select((item, i) => new { Item = item, Index = i })
.First(x => x.Item == search).Index;
解决方案
List<string> xmlValue = new List<string>()
{"English", "Spanish", "French", "Hindi", "English", "English"};
string search = "English";
int[] result = xmlValue.Select((b, i) => b.Equals(search) ? i : -1)
.Where(i => i != -1).ToArray();
这篇关于目录索引搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文