示例#1
0
        public static RateSingleton GetInstance()
        {
            //The approach below ensures that only one instance is created and only
            //when the instance is needed. Also, the uniqueInstance variable is
            //declared to be volatile to ensure that assignment to the instance variable
            //completes before the instance variable can be accessed. Lastly,
            //this approach uses a syncRoot instance to lock on, rather than
            //locking on the type itself, to avoid deadlocks.

            if (uniqueInstance == null)
            {
                lock (syncRoot)
                {
                    if (uniqueInstance == null)
                    {
                        uniqueInstance = new RateSingleton();
                    }
                }
            }
            return(uniqueInstance);
        }
        public double GetRate()
        {
            RateSingleton rate = RateSingleton.GetInstance();

            return(rate.CurrentRate);
        }