NET inside using use

Source: Internet
Author: User

Because of the recent impulse to find a job, he forced himself to review an interview topic every day.

At first the using will understand a function that is to refer to the namespace. When the interviewer heard me answer the question, he asked me right away, what's the effect? I just shook my head, and today I saw the role of using on the net.

1.using instructions. Using + namespace names, such as using System;

2.using aliases. Using + aliases = Specific types that include detailed namespace information.

such as using System;
Using AClass = Namespace1.myclass;
Using Bclass = Namespace2.myclass;

Namespace NameSpace1
{
public class MyClass
{
public override string ToString ()
{
Return "You is in Namespace1.myclass";
}
}
}

Namespace NameSpace2
{
Class MyClass
{
public override string ToString ()
{
Return "You is in Namespace2.myclass";
}
}
}

Namespace Testusing
{
Using NameSpace1;
Using NameSpace2;
<summary>
A summary description of the CLASS1.
</summary>
Class Class1
{
<summary>
The main entry point for 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 ();
}
}
}

3.using statement, defining 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.
For example:

using (Class1 cls1 = new Class1 (), cls2 = new Class1 ())
{
The code using CLS1, CLS2


}//Call the Dispose on CLS1 and CLS2

Here the dispose condition that triggers cls1 and CLS2 is reached at the end of the using statement or throws an exception halfway and controls away from the statement block.

Excerpted from http://www.cnblogs.com/windsails/archive/2004/09/12/42444.html

NET inside using use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.