I have the following system: a "mother" class called DataClass
, has properties and two of them are classes, PartClass
and MemberClass
. In particular, MemberClass
has properties and one of them is a class, SideClass
- with its own properties.
Here is the code sample:
using System;
namespace ConsoleApp
{
public class DataClass
{
public int num { get; set; }
public string code { get; set; }
public PartClass part { get; set; }
public MemberClass member { get; set; }
public DataClass()
{
PartClass part = new PartClass();
MemberClass member = new MemberClass();
}
}
public class PartClass
{
public int seriesNum { get; set; }
public string seriesCode { get; set; }
public PartClass() { }
}
public class MemberClass
{
public int versionNum { get; set; }
public SideClass side { get; set; }
public MemberClass()
{
SideClass side = new SideClass();
}
}
public class SideClass
{
public string firstDetail { get; set; }
public string secondDetail { get; set; }
public bool include { get; set; }
public SideClass() { }
}
Now, I am trying to initialize the DataClass
and assign values to all properties, and this doesn't work.
So, the DataClass
"owns" the PartClass
and the MemberClass
and the MemberClass
itself "sees" the SideClass
which is the bottom class and sort of independent of all.
Here the rest of code:
class Program
{
static void Main(string[] args)
{
DataClass myData = new DataClass()
{
num = 13,
code = "message",
//from here downwards nothing works; error..
part.seriesNum = 1,
part.seriesCode = 7,
member.versionNum = 9,
member.side.firstDetail = "pass",
member.side.secondDetail = "checked",
member.side.include = true;
}
}
}
I thought that by installing constructors and properties the DataClass
instantiation would not have problems, but actually the DataClass
does not see any non-trivial properties (properties referring to classes).
Could someone help me please? Thank you..