Possible Duplicate:
How do I use LINQ Contains(string[]) instead of Contains(string)
Suppose I have the following class and objects:
class Product
{
public int ProductId { get; set; }
public string ProductDesc { get; set; }
}
string[] arrayString = new string []{"A", "B", "C", "D"};
List<Product> products = new List<product>();
Is this code:
var filteredProducts = new List<product>();
foreach(var searchString in arrayString)
{
filteredProducts.Union(Products.Where(p => p.ProductDesc.Contains(searchString)));
}
equivalent to this:
var filteredProducts = products.Where(p => p.ProductDesc.Contains(arrayString.Select(s => s).ToString()));
If that is not the case, how can the first code snippet be rewritten by using LINQ?
No, the equivalent LINQ form is
Talking out loud: