C# 单例

1.代码示例

    public class TempVMs:List
    {
        public TempVMs()
        {
            for (int i = 0; i < PLCData.PipeCount; i++)
            {

                //if (algorithm.UserMath.ToBool(PipeSets.Instance[i].Dv[0]["Lpcvd"]))
                //    Add(new TempLPCVD(i));
                //else
                    Add(new Temp1(i));
            }
        }

        #region singlton
        private static TempVMs _instance;
        private static object _instanceLock = new object();
        private static TempVMs GetInstance()
        {
            lock (_instanceLock)
            {
                return _instance ?? (_instance = new TempVMs());
            }
        }
        public static TempVMs Instance => _instance ?? GetInstance();
        #endregion
    }

你可能感兴趣的:(C#,新手村,c#,开发语言)