C# - 单例模式不起作用

时间:2013-09-05 19:37:17

标签: singleton instance shared

以下是我正在使用的代码:

private static WeightRecordsDataSource sharedDataSource;

public static WeightRecordsDataSource SharedDataSource
        {
            get
            {
                if (sharedDataSource == null)
                    sharedDataSource = new WeightRecordsDataSource();

                return sharedDataSource;

            }

        }

但是,每次调用SharedDataSource时,都会发现sharedDataSource为null!因此调用了新的WeightRecordsDataSource。我做错了什么?

0 个答案:

没有答案