How to use Linq to check if a list of strings contains any string in a list

后端 未结 5 1643
别跟我提以往
别跟我提以往 2021-02-05 07:12

I\'m constructing a linq query that will check is a string in the DB contains any of the strings in a list of strings.

Something like.

query = query.Whe         


        
5条回答
  •  天命终不由人
    2021-02-05 07:25

    I am not quite sure from your question if x.tags is a string or list, if it is a list Jon Skeet's answer is correct. If I understand you correctly though x.tags is a string of strings. If so then the solution is:

    list.Any(x => x.tags.IndexOf(x) > -1)
    

    to count them do

    list.Count(x => x.tags.IndexOf(x) > -1)
    

提交回复
热议问题