Result of LINQ.Any to string

Total Post:24

Points:168

C# 
C#
 1467  View(s)
Ratings:
Rate this:

So, I check if a string contains a certain word from an array with the following statement:

if(stringArray.Any(s => stringToCheck.Contains(s)))


Simple. Now a match is found and the statement is true. But I want to know also which item in the array matched with the string. The placeholder "s" in the LINQ statement above is not available in the following clause.

  1. Re: Result of LINQ.Any to string

    var match = stringArray.FirstOrDefault(s => stringToCheck.Contains(s));
    if(match != null) {
        // match was found
    }


      Modified On Mar-31-2018 06:17:23 AM

Answer

Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.