public class Model { public int Id { get; set; } public string Name { get; set; } } private static List<Model> LinqIn() { List<Model> strList = new List<Model>() { new Model(){Id=1,Name = "张三"}, new Model(){Id=11,Name = "张三1"}, new Model(){Id=2,Name = "李四"}, new Model(){Id=3,Name = "王五"}, new Model(){Id=30,Name = "王五"}, new Model(){Id=4,Name = "赵六"}, }; List<int> whereList = new List<int>() { 1, 3 }; List<Model> list = strList.Where(x => whereList.Contains(x.Id)).ToList(); foreach (var model in list) { Console.WriteLine("Id:" + model.Id + "Name:" + model.Name); } Console.WriteLine("list count=="+list.Count); return list; } //测试 static void Main(string[] args) { List<Model> list = LinqIn(); Console.ReadLine(); }
博客内容主要用于日常学习记录,内容比较随意,如有问题,还需谅解!!!