2010-05-21 112 views
0

我有一個數組...我需要排除這個數組從masterList.customField字符串中的所有項目如下圖所示LINQ查詢過濾DTO

string[] excludeItem = {"a","b","c"}; 

CustomDTO[] masterList = service.LoadMasterList(); 

masterList.Where(c=> masterList.customField NOT IN excludeItem 

如何實現非部分上方?

+0

使用建議的解決方案,你應該想保持你的excludedItem在一個HashSet,而不是一個數組。對於數字較小的數組,可能會更快,但在平均情況下,HashSet.Contains將比Array.Contains – 2010-05-21 20:13:30

回答

3

假設的CustomField是一個字符串:

masterList.Where(c => !excludeItem.Contains(c.customField)); 
0

,或作爲LINQ查詢:

var x = from c in masterList 
     where !excludedItem.Contains(c.CustomField) 
     select c;