Can I define constructor like this? Additional question: Can I call constructor of the class in itself constructor?
class SubArray
{
List<int> array;
string parent;
string name;
SubArray child;
public SubArray(SubArray child, string name)
{
this.child = child;
List<int> array = new List<int>();
this.name = name;
}
}
There is no limit on that, but like any recursion - it needs a stopping condition. otherwise it will cause a stack overflow (PUN intended :)).
I guess you could do something like this and there is no....apparent problem:
public SubArray(SubArray child, string name)
{
this.child = child;
this.array = new List<int>();
this.name = name;
if (child != null && child.child != null)
{
this.child.child = new SubArray(child.child,name);
}
}