我正在制作一个Model类,它应该如下所示:
public class ModelSection
{
public int SectionID { get; set; }
public string SectionName { get; set; }
public string SectionReportName { get; set; }
}我做了一个这样的例子...
ModelSection ms = new ModelSection();
ms.SectionReportName = subreports[0].ToString();
ms.SectionID = SectionID1;
ms.SectionName = SectionName1;
ModelSection ms1 = new ModelSection();
ms1.SectionReportName = subreports[1].ToString();
ms1.SectionID = SectionID2;
ms1.SectionName = SectionName2;
ModelSection ms2 = new ModelSection();
ms2.SectionReportName = subreports[2].ToString();
ms2.SectionID = SectionID3;
ms2.SectionName = SectionName3;有没有更好的方法来做这件事?
发布于 2016-08-25 22:28:03
你可以试着这样做
ModelSection ms = new ModelSection {
SectionReportName = subreports[0].ToString(),
SectionID = SectionID1,
SectionName = SectionName1
};参考:https://msdn.microsoft.com/en-us/library/bb384062.aspx?f=255&MSPPError=-2147217396
发布于 2016-08-25 22:23:29
你可以像下面这样做。
ModelSelection ms1 = new ModelSelection()
{
SectionID = SectionID1,
SectionName = SectionName1,
SectionReportName = subreports[0].ToString()
};
ModelSelection ms2 = new ModelSelection()
{
SectionID = SectionID2,
SectionName = SectionName2,
SectionReportName = subreports[0].ToString()
};https://stackoverflow.com/questions/39147827
复制相似问题