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对象某个字段 var names = strList.Select(t => t.Name).ToList(); //字段值合并 string mergeName = string.Join("|", names.ToArray());
//根据某个字段分组 var types = strList.GroupBy(x => x.Name) .Select(group => new Model { Name = group.Key, }).ToList();
//List中实现类似SQL 查询 select in...
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);
//更改list中某个字段 list.ForEach(o => o.Age = 33); list.All(o => { o.Age = 22; return true; });
//List中获取最大值 int maxA = list.Max(x => x.A);//获取链表中对象属性A的最大值
数组、list转化
List<string> listS=new List<string>(); listS.Add("str"); listS.Add("hello"); string[] str=listS.ToArray(); string[] stauts = dict[0].SDValue.Split('|'); List<string> tempStatus = new List<string>(stauts); where = where.And(o => tempStatus.Contains(o.STATUS));
博客内容主要用于日常学习记录,内容比较随意,如有问题,还需谅解!!!