林克 - .任何类类型列表<string>和类类型字符串



我有两个类

public class Cars
{
public string Car{ get; set; }
public List<string> CarEquipment{ get; set; }
}
public class Customers
{
public string Customer { get; set; }
public string OwnedEquipment{ get; set; }
}

我想检查字符串(类Cars(的公共列表中是否有任何"CarEquipment"eqauls字符串公共字符串"OwnedEquipment(类客户("(布尔真或假(

下面的查询

(Cars.Select(x=>x.CarEquipment).Any(Customers.Select(x=>x.OwnedEquipment).Contains)

不幸的是,由于道具之一是字符串的列表,所以没有完成工作

快速检查:

var cars = new List<Cars>()
{ 
new Cars { Car = "c1", CarEquipment = new List<string> { "a" } }, 
new Cars { Car = "c2", CarEquipment = new List<string> { "a" } }
};
var customers = new List<Customers>() { new Customers { OwnedEquipment = "a" } };
var matchingCars = cars.Where(car => customers.Any(customer => car.CarEquipment.Contains(customer.OwnedEquipment)));
  • 带条件的第一个过滤器(Where(
  • 客户的车载设备与汽车的车载设备列表匹配的条件(car=>customer.Any(customer=>car.CarEquipment.Contains(customer.OwnedEquipment(((

相关内容

最新更新