c# - How to find an index of an element from a list<string>, an element contains a specific part -
this question has answer here:
- get index of lines match linq 3 answers
i have list, contains.
1. house. 2. writing pen.
now want know @ index string contains house(1.) how without loop? array.indexof not work not find element same match
an elegant way use findindex
list<string> examplelist = new list<string>(); examplelist.add("this house."); examplelist.add("i writing pen"); int index = examplelist.findindex(x => x.contains("house")); console.writeline(index); //0 index = examplelist.findindex(x => x.contains("pen")); console.writeline(index); //1
findindex searches element matches conditions defined specified predicate, , returns zero-based index of first occurrence within list or portion of it.
Comments
Post a Comment