2015-03-18 68 views
1

查找兩個列表的交集我有以下對象(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#我怎麼找到這些列表,其中,例如,名稱中包含「用戶」和JOBTITLE =「管理員」的交集。
另一個例子是where department = finance AND jobtitle = admin AND location = building1。
我已經簡化了問題的清晰度,但每個對象將有10個屬性,我會有10個列表。任何屬性組合都可以用作搜索條件。

+0

。凡(I => i.department == '金融' && i.jobtitle = '管理員')等等等等 – 2015-03-18 20:47:03

+0

也許http://stackoverflow.com/questions/4248433/intersect-two-數組交叉。 – 2015-03-18 20:47:48

+0

。它在哪裏 - 謝謝Sythnet P – cymorg 2015-03-18 21:09:33

回答

1
var User = UserBatch1.FirstOfDefault(i => i.department == "finance" && i.jobtitle = "admin");