Answer the question
In order to leave comments, you need to log in
How to shorten this code?
I have a search in some columns, I wrote it like this:
SearchPredicate = ( lEntry, searchText ) =>
lEntry.Message.Contains( searchText, StringComparison.OrdinalIgnoreCase ) ||
lEntry.Sender.Contains( searchText, StringComparison.OrdinalIgnoreCase ) ||
lEntry.Level.Contains( searchText, StringComparison.OrdinalIgnoreCase );
Answer the question
In order to leave comments, you need to log in
If you're really stubborn, you can do something like this:
new[] { lEntry.Message, lEntry.Sender, lEntry.Level }
.Any(x => x.Contains(searchText, StringComparsion.OrdinalIgnoreCase)
public static bool IsSubstringOfAny(this string search, params string[] samples) =>
samples.Any(x=>x.Contains(search, StringComparsion.OrdinalIgnoreCase));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question