1.using instructions. Using + namespace name. The namespace name can be either a system or a class of its own definition.
2.using aliases. Using + aliases = Specific types that include detailed namespace information.
Conditions: When the same. cs file references two different namespaces, but two namespaces include a type of the same name
Format:
using
System;
using
aClass = NameSpace1.MyClass;
using
bClass = NameSpace2.MyClass;
Using namespace1{//define class}using namespace2{//define Class}3.using statement, define a scope and process the object at the end of the range. When an instance of a class is used in a code snippet, it is hoped that, for whatever reason, the dispose of the class instance is automatically invoked to release the resource, as long as it leaves the code snippet.
To achieve this goal, it is also possible to use try...catch to catch anomalies, but it is also convenient to use using. Example: Click on a button in the 1 Windows Form to draw a hint
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespaceprogram{ Public Partial classForm_main:form { PublicForm_main () {InitializeComponent (); }Private voidBtn_click (Objectsender, EventArgs e) {using(NewTest ())//to create a test object in a using statement{}//the Dispose method of the test object is automatically called after execution of the using statement block is completed}classTest:idisposable//defining the test class to implement the IDisposable interface{ Public voidDispose ()//Implementing interface Methods{MessageBox.Show ("the Dispose method of the test object has been executed","Tips");//Pop-up message dialog box} }}}
2 • Console Application
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.IO;namespaceuseusing{classProgram {Static voidMain (string[] args) {using(Myusing mu =Newmyusing ()) {} console.readline (); }}classmyusing:idisposable { Public voidDispose ()//Implementing interface Methods {Console.WriteLine ("Dispose is called"); }}}
Usage of using