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; }
}
生命中最值得欣慰的,莫过于一觉醒来,你还在身旁

浙公网安备 33010602011771号