A. NET object usage is generally divided into three kinds of situations:
1. Creating objects
2. Using objects
3. Releasing objects
Two. Creating objects
1. The creation of objects is actually divided into two steps: variable type declaring and initializing an object
2. Variable type declaration (declare), such as:
FileStream FS
This line of code creates a variable called FS in the current variable scope space (stack or heap), at least four bytes (because you want to save an object's address)
3. Initializing objects
Object must be initialized before it is used (calling its methods or properties).
As
FS = new FileStream (@ "C:\test.txt", FileMode.OpenOrCreate);
This line of code is divided into 3 steps:
A. Allocate a piece of memory in the managed heap that is equal to the sum of all the fields in the FileStream (excluding static, of course) plus the other Dongdong that Ms deems necessary.
B. Initialize the field of the object (the value type has all the bits initialized to 0, the object initialized to null, of course string is an exception, it is initialized to an empty string)
C. Call FileStream the corresponding constructor, where a private field of an unmanaged resource (file) is initialized.
Three. Using objects
Using an object is nothing, it means calling the object's methods (or attributes, and so on) to complete a function of course the method invoked to release the object should not be within this category (now referred to finalize, etc.)