我有以下項目Lambda多個條件來驗證對象列表中的列表?
List<person> lst = new List<person>()
lst.Add(new person(){ name="abc", age="24" });
lst.Add(new person(){ name="xyz", age="25" });
lst.Add(new person(){ name="zxc", age="28" });
lst.Add(new person(){ name="wer", age="38" });
List<string> strlst = new List<string>();
strlst.Add("abc");
strlst.Add("zxc");
現在我確認名單
lst.Exists(a => strlst.Contains(a.name))
我如何驗證整個列表,如果它包含「ABC and
xyz`兩者組成的列表?
請注意,這是一個相當低效的操作,因爲您正在爲您搜索的每個字符串執行所有人員的線性搜索,所以它不能很好地適用於大數據集。對於小數據集,它會很好。 – Servy 2013-02-21 14:54:40
你能提出任何其他方法嗎? – Pravin 2013-02-21 15:05:14
@Pravin當然,請看我的答案。 – Servy 2013-02-21 15:08:39