Using:
1. equivalent to the Java import function and introduced functions;
2. When clearing resources, use the using keyword for deterministic termination;
The time for using is when the object uses unmanaged resources or valuable resources,
For managed or non-precious resources, I can rely on GC, and there is no need to add myself. In addition, try blocks will affect efficiency.
The Using statement defines a range to process objects at the end of the range.
Scenario:
WhenCodeThe class instance is used in the section, and you want to automatically call the dispose of the class instance as long as you leave the code segment for whatever reason.
To achieve this goal, it is also possible to catch exceptions using try... catch, but it is also convenient to use using.
The object provided for the using statement must implement the idisposable interface. This interface provides the dispose method, which releases the resources of this object.
Essence of using statements
The IL code generated using the using statement is actually a try, finally code block, releasing resources in the finally code block.
3. Using alias. Using + alias = contains the specific type of detailed namespace information.
This method has the advantage that when the same CS references two different namespaces, but both namespaces contain the same name type. When this type is required, the detailed namespace method should be used in every place to distinguish the types with the same name. The alias method is more concise. You can declare the alias for the class you use.
New:
1. First, the new modifier and the new operator are two concepts. The new modifier can only be used to inherit classes and make up for the shortcomings of the base class design. The new operator is used to instantiate a type;
2. The new modifier and override are mutually exclusive in meaning listing, so they cannot act on the same member;