找不到合适的方法来覆盖toString

时间:2016-04-05 18:32:02

标签: string override

class Persoana
    {
        public string name;
        public Persoana[] children;

        Persoana(string nume, Persoana[] copii) {
            this.name = name;
            this.children = children;
        }

        public override string toString() {   //what is wrong in this function?
            string temp = null;
            for (int i = 0; i < this.children.Length; i++)
                temp = temp + this.children[i].name;    //I don' know how to do it with a string.join in this case
            return string.Format("Parent name: {0}  Number of children: {1}   Children: {2}", name, children.Length);
        }
    }

1 个答案:

答案 0 :(得分:1)

我认为你需要输入'String',而不是'string'。