linq - C# String.IndexOf returns only one element when result from list is may -
i have list of strings, retrieved database , wanted filter list list items have text contained in them. string.contain have been perfect case sensitive. expect many results returned 1 is. here code snippet
if (!string.isnullorwhitespace(searchterm)) list = list.where(a => a.description.indexof(searchterm, stringcomparison.ordinalignorecase) >= 0 || a.part.modulename.indexof(searchterm) >= 0).tolist();
i appreciate in figuring out whats going on.
you're ignoring case on first of 2 calls indexof
. removing expected results.
try adding both:
if (!string.isnullorwhitespace(searchterm)) { list = list.where(a => a.description.indexof(searchterm, stringcomparison.ordinalignorecase) >= 0 || a.part.modulename.indexof(searchterm, stringcomparison.ordinalignorecase) >= 0).tolist(); }
Comments
Post a Comment