Is this Singleton implementation correct and thread-safe?

后端 未结 4 2144
北荒
北荒 2020-12-15 12:14

Is this singleton implementation correct and thread-safe?

class Class
{
    public static readonly Class Instance;

    static Class()
    {
        Instance         


        
4条回答
  •  情歌与酒
    2020-12-15 13:06

    You should do the initialization in the variable declaration:

    public static readonly Class Instance = new Class();
    

提交回复
热议问题