Example: Using System; Usually appear in the *.cs.
2.using aliases. Using + aliases = Specific types that include detailed namespace information.
One advantage of this approach is that when the same CS references two different namespaces, but two namespaces include a type of the same name. When this type is needed, it is necessary to distinguish the types of the same names in each place using the detailed namespace method. The alias method will be more concise, which class will be used to give the class alias declaration. Note: Not that two names are duplicated, one is aliased, the other does not need to be aliased, and if two are to be used, two of them need to use a using to define the alias.
Using system;using AClass = namespace1.myclass;using Bclass = Namespace2.myclass; Namespace namespace1{public class MyClass {public override string ToString () {return ' Yo U is in Namespace1.myclass "; }}} namespace namespace2{class MyClass {public override string ToString () {return ' Y OU is in Namespace2.myclass "; }}} namespace testusing{using NameSpace1; Using NameSpace2; <summary>///CLASS1 Summary description. </summary> class Class1 {///<summary>//The main entry point of the application. </summary> [STAThread] static void Main (string[] args) {/////TODO: Add code here to launch the application//AClass my1 = new AClass (); Console.WriteLine (MY1); Bclass my2 = new Bclass (); Console.WriteLine (MY2); Console.WriteLine ("Press any Key"); Console.read (); } }}
A 3.using statement that defines a range that handles objects at the end of a range.
Scene:
When an instance of a class is used in a code snippet, it is hoped that, for whatever reason, the dispose of this class instance will be called automatically whenever you leave this 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.
using (Class1 cls1 = new Class1 (), cls2 = new Class1 ()) { //The code using CLS1, CLS2}//Call the Dispose on CLS1 and Cls2
Using three ways to use the C # learning notes