FilePrefixList.Any(s => FileName.StartsWith(s))
Can I get s
value here? I want to display the matched string.
Not with Any
, no... that's only meant to determine whether there are any matches, which is why it returns bool
. However, you can use FirstOrDefault
with a predicate instead:
var match = FilePrefixList.FirstOrDefault(s => FileName.StartsWith(s));
if (match != null)
{
// Display the match
}
else
{
// Nothing matched
}
If you want to find all the matches, use Where
instead.
See more on this question at Stackoverflow