Unity - A计划(永久有效期) 扫二维码继续学习 二维码时效为半小时

(207评价)
优惠后 ¥1899.00优惠前 ¥2499.00 双十一全年最大力度限时优惠
1对1 答疑即时回复7天无理由退款30天价保提问必答

服务保障

1对1 答疑

提供专属的一对一在线答疑,快速答疑解惑。

即时回复

及时响应学习咨询,帮助解决问题。

7天无理由退款

购买后7天内可申请无理由退款。

30天价保

购买后30天内如遇降价,可申请价保。

提问必答

对于提问做到有问必答,帮您扫清学习过程中的种种障碍

为什么list中添加元素却还是返回空?
春华发起了问答2020-11-28
1
回复
821
浏览

我在网上复制的单例A,然后用一个类B去继承A, B的一个属性就是list<T> C,我在构造函数中初始化C并添加了元素,为什么还是返回null?

具体代码:  

public sealed class CharacterManager : Singleton<CharacterManager>
{
    private List<Character> m_totalcharacterlist;
    public List<Character> TotalCharacterList
    {
        get { return m_totalcharacterlist; }
        set { m_totalcharacterlist = TotalCharacterList; }
    }

    public CharacterManager()
    {
        Debug.Log("0");
        TotalCharacterList = new List<Character>
        {
            new Character("the spirit of peach blossom", false),
            new Character("the girl with a bird", false),
            new Character("the vampire bat", false),
            new Character("the saber of killing demon", true),
            new Character("the spirit of snake", false),
            new Character("the female general ", false),
            new Character("the spirit of blade", false),
            new Character("the girl with a bird", false),
            new Character("the imperial heir", true),
        };
        Debug.Log(TotalCharacterList);
        Debug.Log("0.1");
    }
}

所有回复
  • 老师_Trigger • 2020-11-29

    同学你好,可以参考一下:

    https://m.wenda.so.com/q/1534043066216378

    https://blog.csdn.net/ivan2015/article/details/79799831

    http://www.jiaonan.tv/html/blog/1/29606.htm

    还有-5条回复,点击查看
    你还没有登录,请先登录或注册!
发表回复
你还没有登录,请先 登录或 注册!