递归类C# [英] Recursive class C#

查看:85
本文介绍了递归类C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以这样定义构造函数吗?附加问题:我可以自己调用类的构造函数吗?

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;
    }
}

推荐答案

对此没有限制,但是像任何递归一样,它需要一个停止条件.否则会导致堆栈溢出(PUN意图:)).

There is no limit on that, but like any recursion - it needs a stopping condition. otherwise it will cause a stack overflow (PUN intended :)).

这篇关于递归类C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆