C# 如何将两个类合并为一个单元? List Lrdi=new List(); ReportDataInfo rdi=新的ReportDataInfo(); ReportDataInfo RdiMerge=新的ReportDataInfo(); 字符串[]AccountTypeCodeCustomArray= AccountCodeTypeCustom.Split(“,”.ToCharArray()); 字符串[]子类型CodeCustomArray= SubAccountTypeCodeCustom.Split(“,”.ToCharArray()); 字符串[]AccountCodeCustomArray=AccountCodeCustom.Split(“,”.ToCharArray()); for(int i=0;i
这是我以前尝试过的事情 现在我的问题是 我希望合并从ExportDataToCSV.GetLedgerReportData()返回ReportDataInfo强> 无论从ExportDataToCSV.GetLedgerReportData()返回什么值,我都被困在这里强> 我想合并到单个ReportDataInfo中,然后传递到CurrentSessionInfo.ReportData=RdiMerge强> ReportDataInfo看起来像C# 如何将两个类合并为一个单元? List Lrdi=new List(); ReportDataInfo rdi=新的ReportDataInfo(); ReportDataInfo RdiMerge=新的ReportDataInfo(); 字符串[]AccountTypeCodeCustomArray= AccountCodeTypeCustom.Split(“,”.ToCharArray()); 字符串[]子类型CodeCustomArray= SubAccountTypeCodeCustom.Split(“,”.ToCharArray()); 字符串[]AccountCodeCustomArray=AccountCodeCustom.Split(“,”.ToCharArray()); for(int i=0;i,c#,asp.net,.net,linq,list,C#,Asp.net,.net,Linq,List,这是我以前尝试过的事情 现在我的问题是 我希望合并从ExportDataToCSV.GetLedgerReportData()返回ReportDataInfo 无论从ExportDataToCSV.GetLedgerReportData()返回什么值,我都被困在这里 我想合并到单个ReportDataInfo中,然后传递到CurrentSessionInfo.ReportData=RdiMerge ReportDataInfo看起来像 List<ReportDataInfo> Lrd
List<ReportDataInfo> Lrdi = new List<ReportDataInfo>();
ReportDataInfo rdi = new ReportDataInfo();
ReportDataInfo RdiMerge=new ReportDataInfo();
string[] AccountTypeCodeCustomArray =
AccountCodeTypeCustom.Split(",".ToCharArray());
string[] SubTypeCodeCustomArray =
SubAccountTypeCodeCustom.Split(",".ToCharArray());
string[] AccountCodeCustomArray = AccountCodeCustom.Split(",".ToCharArray());
for (int i = 0; i < AccountCodeTypeCustom.Length; i++)
{
rdi = ExportDataToCSV.GetLedgerReportData(Globals.GetInt(
AccountTypeCodeCustomArray[i],0),Globals.GetInt(
SubTypeCodeCustomArray[i],0),Globals.GetInt( AccountCodeCustomArray[i],0),
this.CurrentSessionInfo.Company.CompanyCode,
this.CurrentSessionInfo.FinancialYear.StartDate,
this.CurrentSessionInfo.FinancialYear.EndDate);
// Lrdi.Add(rdi);
RdiMerge.Rows.Concat(rdi.Rows);
//RdiMerge.ReportHeading = rdi.ReportHeading;
//RdiMerge.Rows = rdi.Rows;
}
CurrentSessionInfo.ReportData = RdiMerge;
[可序列化]
公共类ReportDataInfo
{
公共字符串报告标题{get;set;}
公共列表行{get;set;}
}
它只需使用Automapper即可
AutoMapper是一个对象到对象映射器,它允许您解决将一个类型的对象中的相同属性映射到另一个类型的对象的问题。例如,可以使用AutoMapper自动将重实体Customer对象映射到CustomerTohello jayraj您能给我举个例子吗?
List
有一个AddRange()
方法。你试过了吗?没有@EladLachmi的例子对我来说太好了-关于列表的AddRange
的MSDN页面。其思想是AddRange
获取一个IEnumerable
,并将其附加到列表的末尾。这就是你想要的,对吗?还是我误解了?
[Serializable]
public class ReportDataInfo
{
public string ReportHeading { get; set; }
public List<ReportColumnInfo> Rows { get; set; }
}