How can a readonly static field be null?

后端 未结 5 857
误落风尘
误落风尘 2020-12-30 21:37

So here\'s an excerpt from one of my classes:

    [ThreadStatic]
    readonly static private AccountManager _instance = new AccountManager();

    private Ac         


        
5条回答
  •  长情又很酷
    2020-12-30 22:10

    I believe what is happening is that the static field is only being initialized once so when another thread tries to read the field it will be null (since its the default value) because _instance can't be initialized again. Its just a thought but and I could be totally way off but that's what I think is happening.

提交回复
热议问题