简体   繁体   English

使用Lambda搜索字符串数组

[英]Using Lambda to search for an array of strings

I've got a generic list (vwsearch) with a string field (ProductSearch) in it . 我有一个通用列表(vwsearch),其中有一个字符串字段(ProductSearch)。 And an array of strings (stringarray) 和一个字符串数组(stringarray)

How would I search through my list for the records where the string field equals or contains all of the string values in the array. 我将如何在列表中搜索字符串字段等于或包含数组中所有字符串值的记录。 I've got the following code which returns the records where the ProductSearch field contains any of the strings values in the array. 我有以下代码,该代码返回记录,其中ProductSearch字段包含数组中的任何字符串值。

vwsearch = vwsearch.Where(v=>v.ProductSearch.Contains(stringarray.Last()))

怎么样

vwsearch = vwsearch.Where(v => stringarray.All(s => v.ProductSearch.Contains(s)))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM