• C# List分组(IGroup)


        static void Main(string[] args)
            {
                List<BankAccountFile> fileList = new List<BankAccountFile>
                {
                     new BankAccountFile{   BankCode= "ICBC",
            BankAccountNum= "1001222309024",
            Period="202105",
            BankAcctPath="D:\SEPC.FSSC.ReceiptFile\ICBC\DZD\month\1001222309024_202105_page1_001.html"
                     },
                      new BankAccountFile{   BankCode= "ICBC",
            BankAccountNum= "1001222309024",
            Period="202105",
            BankAcctPath="D:\SEPC.FSSC.ReceiptFile\ICBC\DZD\month\1001222309024_202105_page1_002.html"
                     },
                       new BankAccountFile{   BankCode= "ICBC",
            BankAccountNum= "1001222309024",
            Period="202105",
            BankAcctPath="D:\SEPC.FSSC.ReceiptFile\ICBC\DZD\month\1001222309024_202105_page1_003.html"
                     },
                        new BankAccountFile{   BankCode= "ICBC",
            BankAccountNum= "1001222309024",
            Period="202105",
            BankAcctPath="D:\SEPC.FSSC.ReceiptFile\ICBC\DZD\month\1001222309024_202105_page1_004.html"
                     },
                           new BankAccountFile{   BankCode= "ICBC",
            BankAccountNum= "1001222309024",
            Period="202106",
            BankAcctPath="D:\SEPC.FSSC.ReceiptFile\ICBC\DZD\month\1001222309024_202106_page1_001.html"
                     },
                                     new BankAccountFile{   BankCode= "ICBC",
            BankAccountNum= "1001222309024",
            Period="202106",
            BankAcctPath="D:\SEPC.FSSC.ReceiptFile\ICBC\DZD\month\1001222309024_202106_page1_002.html"
                     },
                                      new BankAccountFile{   BankCode= "ICBC",
            BankAccountNum= "1001222309024",
            Period="202106",
            BankAcctPath="D:\SEPC.FSSC.ReceiptFile\ICBC\DZD\month\1001222309024_202106_page1_002.html"
                     }
                 };
    
                List<BankAccountFile> newList1 = new List<BankAccountFile>(); 
                foreach (IGrouping<string, BankAccountFile> group in fileList.GroupBy(c => c.Period))
                {
    
                    BankAccountFile model = new BankAccountFile();
                    model.Period = group.Key; 
                    foreach (BankAccountFile stu in group.OrderBy(a => a.Period))
                    {
                        Console.Write(stu.BankAcctPath + ";");
                        model.BankCode = stu.BankCode;
                        model.BankAccountNum = stu.BankAccountNum;
                        model.BankAcctPath = stu.BankAcctPath; 
                    }
                    model.FileList = group.OrderBy(a => a.Period).ToList();
                    newList1.Add(model); 
                } 
            }
    
            public class BankAccountFile
            {
                /// <summary>
                /// 银行简码
                /// </summary>
                public string BankCode { get; set; }
                /// <summary>
                /// 银行账号
                /// </summary>
                public string BankAccountNum { get; set; }
                /// <summary>
                /// 期间
                /// </summary>
                public string Period { get; set; }
                /// <summary>
                /// 下载路径
                /// </summary>
                public string BankAcctPath { get; set; }
    
                /// <summary>
                /// 银行账号名称
                /// </summary>
                public string BankAccountName { get; set; }
    
                /// <summary>
                /// 组装多条数据的List
                /// </summary>
                public List<BankAccountFile> FileList { get; set; }
            }
    

      

    生命中最值得欣慰的,莫过于一觉醒来,你还在身旁
  • 相关阅读:
    Python操作 RabbitMQ、Redis、Memcache、SQLAlchemy
    Twsited异步网络框架
    MySQL-python模块
    python3安装Fabric模块
    PInvoke.net Visual Studio Extension
    资源下载站
    WPF RTSP存储到一个文件中的位置
    Windows 7 中未能从程序集System.ServiceModel
    无法在WEB服务器上启动调试,Web 服务器配置不正确
    CS0016: 未能写入输出文件“c:WINDOWSMicrosoft.NETFramework.。。”--“拒绝访问
  • 原文地址:https://www.cnblogs.com/chaonuanxi/p/15379442.html
Copyright © 2020-2023  润新知