How can a readonly static field be null?

后端 未结 5 838
误落风尘
误落风尘 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-30 22:23

    You've hit a classic [ThreadStatic] "101" here.

    The static initializer will only fire once, even though it is marked as [ThreadStatic], so other threads (apart from the first) will see this uninitialised.

提交回复
热议问题