检查列表是否包含在字符串 属性 中?

Checking if a list is included in a property which is a string?

场景 我有一个 class 具有不同数量的属性。其中之一是字符串。

OBJECTIVE 检查该属性中是否包含字符串列表。

示例 字符串属性可以是对汽车的描述,例如:

"Chevrolet 100 has 3000cc, using 250Cv. The 55/95 tires are included in the price. Just for 2 PAX... etc ..."

检查清单可以是:

"3000cc", "250Cv", "55/95 tires"

所以我的代码是:

         Class_A
int      id
int      price
string   definition

Class_A car = new Class_A()
{
    id = 1,
    price = 100000,
    definition = "Chevrolet 100 has 3000cc, using 250Cv. The 55/95 tires are 
    included in the price. Just for 2 PAX... etc ..."
}

List<string> checkingList = new List<string>();
checkingList.Add("3000cc");
checkingList.Add("250Cv");
checkingList.Add("55/95 tires");

作为我试过的例子:

bool sucess;
sucess = car.Select(p => p.definition.Contains(checkingList)).FirstorDefault();
sucess = car.Select(p => p.Where(o => o.definition.Contains(checkingList)).FirstorDefault();
sucess = car.Select(p => p.Where(o => o.definition.ForEach.Contains(checkingList)).FirstorDefault();

在此先感谢伙伴们。

假设您有一个名为 carsList<Class_A>,使用 Any 方法检查是否在 definition 中找到 checkingList 中的任何项目属性:

cars.Select(p => checkingList.Any(y => p.definition.Contains(y)).FirstorDefault();

如果您需要确保 checkingList 中的每个字符串都在 definition 属性 中,请使用 All 而不是 Any