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; }
}