日期:2014-05-18 浏览次数:21134 次
class Program { static void Main(string[] args) { List<string> ls = new List<string>(){ "aa","bb","cc" }; List<people> lp = new List<people>(){ new people{name="aa",age="1"}, new people{name="a",age="1"}, new people{name="bb",age="1"}, new people{name="dd",age="1"}, }; } //问题: //如何查出lp中的name存在于ls中的people列表? //结果: people{name="aa",age="1"},people{name="bb",age="1"}, } public class people { public string name; public string age; }
List<string> ls = new List<string>(){ "aa","bb","cc" }; List<people> lp = new List<people>(){ new people{name="aa",age="1"}, new people{name="a",age="1"}, new people{name="bb",age="1"}, new people{name="dd",age="1"}, }; var namequery = from xx in lp where ls.Contains(xx.name) select xx; foreach (people resultname in namequery) { MessageBox.Show(resultname.name + " " + resultname.age); }