欢迎莅临 SUN WU GANG 的园子!!!

世上无难事,只畏有心人。有心之人,即立志之坚午也,志坚则不畏事之不成。

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  470 随笔 :: 0 文章 :: 22 评论 :: 30万 阅读
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
复制代码
            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());                        
复制代码

 

1
2
3
4
5
6
//根据某个字段分组 
var types = strList.GroupBy(x => x.Name)
                      .Select(group => new Model
                      {
                          Name = group.Key,
                      }).ToList();

 //List中实现类似SQL 查询  select in...

1
2
3
4
5
6
7
8
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);   

 

1
2
3
4
//更改list中某个字段
list.ForEach(o => o.Age = 33);
 
list.All(o => { o.Age = 22; return true; });
1
2
//List中获取最大值
int maxA = list.Max(x => x.A);//获取链表中对象属性A的最大值

 数组、list转化

1
2
3
4
5
6
7
8
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));

  

 

 

  

posted on   sunwugang  阅读(3418)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
历史上的今天:
2019-03-21 VS2012 统计代码行数
2018-03-21 自定义控件添加事件
点击右上角即可分享
微信分享提示