Sid Broklyn Sid Broklyn - 1 year ago 66
C# Question

Best way to create a entity in c#

I am making a

class which should look like this:

public class ModelSection
public int SectionID { get; set; }
public string SectionName { get; set; }
public string SectionReportName { get; set; }

I am making a instance of it like this...

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;

Is there a better way to do this? Thanks.

Answer Source

You can try doing this

 ModelSection ms = new ModelSection {
                    SectionReportName = subreports[0].ToString(),
                    SectionID = SectionID1,
                    SectionName = SectionName1


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download