使用多个搜索词查找两个列表的交集
Find the intersection of two lists using multiple search terms
我有以下对象(以 JSON 格式显示)
UserBatch1{
User{ name: user1; jobtitle: admin; department: finance; location: building1; extn: 1234}
User{ name: user2; jobtitle: techie; department: engineering; location: building2; extn: 4321}
User{ name: user3; jobtitle:boss; department:management: location: building3; extn: 5555}
}
UserBatch2{
User{ name: user1; jobtitle: admin; department: finance; location: buildlig1 extn: 1234}
User{ name: user4; jobtitle: techie; department: manufacturing; location: building4; extn: 8888}
User{ name: user5; jobtitle: admin; department: management; location: building1; extn: 7777}
}
对象包含在列表中,例如
List<User> UserBatch1;
List<User> UserBatch2;
使用 C# 如何找到这些列表的交集,例如,名称包含 "user" AND jobtitle = "admin".
另一个例子是 department = finance AND jobtitle = admin AND location = building1.
为了清楚起见,我简化了问题,但每个对象将有 10 个属性,我将有 10 个列表。任何属性组合都可以用作搜索条件。
var User = UserBatch1.FirstOfDefault(i => i.department == "finance" && i.jobtitle = "admin");
我有以下对象(以 JSON 格式显示)
UserBatch1{
User{ name: user1; jobtitle: admin; department: finance; location: building1; extn: 1234}
User{ name: user2; jobtitle: techie; department: engineering; location: building2; extn: 4321}
User{ name: user3; jobtitle:boss; department:management: location: building3; extn: 5555}
}
UserBatch2{
User{ name: user1; jobtitle: admin; department: finance; location: buildlig1 extn: 1234}
User{ name: user4; jobtitle: techie; department: manufacturing; location: building4; extn: 8888}
User{ name: user5; jobtitle: admin; department: management; location: building1; extn: 7777}
}
对象包含在列表中,例如
List<User> UserBatch1;
List<User> UserBatch2;
使用 C# 如何找到这些列表的交集,例如,名称包含 "user" AND jobtitle = "admin".
另一个例子是 department = finance AND jobtitle = admin AND location = building1.
为了清楚起见,我简化了问题,但每个对象将有 10 个属性,我将有 10 个列表。任何属性组合都可以用作搜索条件。
var User = UserBatch1.FirstOfDefault(i => i.department == "finance" && i.jobtitle = "admin");