c# - How to find an index of an element from a list<string>, an element contains a specific part -


this question has answer here:

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

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -