In fact, I still know this keyword when I look at Terrylee's Singleton mode!
Let's take a look at msdn's explanation: http://msdn.microsoft.com/zh-cn/library/x13ttww7.aspx
The volatile keyword indicates that a field can be modified by multiple concurrent threads. Fields declared as volatile are not restricted by Compiler Optimization (assuming that they are accessed by a single thread. This ensures that the field displays the latest value at any time.
The volatile modifier is usually used for fields accessed by multiple threads but not serialized by using the lock statement. For examples of using volatile in A multithreaded solution, see How to: create and terminate a thread (C # programming guide ).
The volatile keyword can be applied to the following fields:
Reference type.
Pointer type (in an insecure context ). Note that although the pointer itself can be variable, the object it points to cannot be variable. In other words, you cannot declare a pointer to a mutable object ".
Integer, such as sbyte, byte, short, ushort, int, uint, char, float, and bool.
An Enumeration type with an integer base type.
It is known that it is a generic parameter of the reference type.
IntPtr and UIntPtr.
Variable keywords can only be applied to class or structure fields. Local variables cannot be declared as volatile.
Paste Terrylee's Code directly: (tailism)
Using System; namespace SigletonPattern. Sigleton {// <summary> // What is the result? Yes? :? In? C # use? Double? ? Lock? OK? Real? Now? Single? ? Module? ? /// Edit? Write? :? Terrylee // day? Period? :? Year? Month? ? /// </Summary> public class DoubLockSigleton {private static volatile DoubLockSigleton instance; /// <summary> // auxiliary? Help? Lock? Right? Like ?,? Ben? Body? No? Yes? Meaning? ? /// </Summary> private static object syncRoot = new Object (); // <summary> /// what is the structure? Creation? Fang? Method? Change? Is it? Private /// </summary> private DoubLockSigleton () {} public static DoubLockSigleton Instance {get {if (instance = null) {lock (syncRoot) {if (instance = null) instance = new DoubLockSigleton () ;}} return instance ;}
} }}
Volatile I still don't quite understand his purpose! First understand this keyword! Hey
Technorati labels: volatile, asp.net