【发布时间】:2015-08-14 10:11:28
【问题描述】:
在LINQe.g.中有很多搜索多个字符串值的好例子
public static Product[] GetProducts(Guid[] prodIDs)
{
return (from p in GetProducts()
where prodIDs.Contains(p.ProductID)
select p).ToArray<Product>();
}
我有一个需要从客户那里匹配的产品列表, 但我没有完全匹配 - 客户产品列表包含我的 ProductID - 但它不准确 - 例如
Customer MyCompany
Description Description
Prod1XY Prod1
AProd2B Prod2
XXXProd3 Prod3
因此我无法从 prodIDs [字符串数组] 中过滤,因为 Prod1 不包含 Prod1XY
因此无法使用可用的示例。
我怎样才能有效地改变(反转)工作示例 请搜索包含我的产品描述的 CustomerProducts?
所以要确认:这不是重复的。示例使用string[] x
输入参数然后搜索:
其中x.contains
我需要帮助才能得到它:myProducts.Contains(x)
另一个在线示例修改以显示情况:
static void Main(string[] args) {
var table = new[] {
new { uid = 1 },
new { uid = 2 },
new { uid = 3 },
new { uid = 4 },
new { uid = 5 }
};
var stringarray = new[] { "1", "5", "10" };
var results = from xx in table
where table.Contains(stringarray)
select xx;
foreach (var result in results) {
Console.WriteLine("Result: " + result.uid.ToString());
}
}
【问题讨论】: