Mail: zsc771120@yahoo.com.cn
First look at the following code:
Using (Form_arg Arg = New Form_Arg (this.ip, this.port, this.limit)
{
Arg.Left = this.left 30;
Arg.top = this.top 25;
Arg.showdialog ();
Arg.get (Out this.ip, out this.port, out this.limit);
}
I used to use "use system;" or "useing system.io", etc., I haven't used the code, I don't know what this code means, so I've read MSDN, there is the following explanation:
Using can get one or more resources to perform a statement, then dispose of (Dispose).
Using (resource capture) embedded statement
Using (ResourceType Resource = Expression) Statement
The above explanation is already clear, and the name of the resource is written in the brackets behind us, and the resource is automatically cleared after the code is handled in the code. The following is an example of MSDN:
The example will establish a name
Log.txt file, and write two lines of text into the file. Next, this example will turn on the same file to read the text line contained, and copy the text line to the main control station.
Using system;
Using system.io;
Class test
{
Static void main () {
Using (TextWriter W = file.createtext ("log.txt")) {
W.WriteLine ("this is line one");
W.WriteLine ("this is line two");
}
Using (TextReader R = file.opentext ("log.txt")) {
String S;
While ((s = R.Readline ())! = null) {
Console.WriteLine (s);
}
}
}
}
Because the TextWriter and the TextReader category will work on the IDisposable interface, this example can be used to confirm that the basic files after writing or reading the job correctly have been properly turned off. Here is the description of MSDN:
When you write the program of the item that uses the package resource, you should determine the Dispose method that calls the object when the item is used. You can use the C # USING statement, or other TRY / FINALLY block in the program language for the Common Language Runtime to perform this action.
C # USING statement
C # program language Using statement will call the Dispose method in a more automatic mode by simplifying the program code written to establish and clear the object. The USING statement will get one or more resources, perform the statements you specify, and then dispose of the object. Note that the use of uses of the USING is useful for the object of the object of the object does not exceed the method of constructing the object. The following program examples create and clear the ReserveWrapper category to perform an individual, as previously provided in the C # actual DISPOSE method example.
Class myapp
{
Public static void main ()
{
Using (resourceWrapper r1 = new resourceWrapper ())
{
// do sometying with the object.
R1.DOSMETHING ();
}
}
}
The front contained program code is equivalent to the following scenarios. Class myapp
{
Public static void main ()
{
ResourceWrapper r1 = new resourceWrapper ();
Try
{
// do sometying with the object.
R1.DOSMETHING ();
}
Finally
{
// Check for a null resource.
IF (r1! = null)
// Call The Object's Dispose Method.
r1.dispose ();
}
}
} USING statement can obtain one or more resources, perform a statement, then dispose of (Dispose).
Using statement:
Using
Resource capture)
Embedded statement
Resource capture:
Regional variable announcement
Arithma
The resource is the category or structure of the SYSTEM.IDISPOSable, which contains a single unparalleled method called Dispose. The program of the resource can call Dispose to indicate that the resource is no longer needed. If the Dispose is not called, the automatic disposal will occur due to memory recycling. If the resource captured form is the region variable, the type of zone variable declaration must be system.idisposable or can be intended to convert to System.IDisposable. If the resource capture form is an arithmetic, this arithmetic must be used for system.idisposable type or can be integrated into system.idisposable type. The area variable declared in the resource capture is only read, and it is necessary to include an initial setting. If the embedded statement attempts to modify these area variables (transfers through setting or and - operator), or transder them as a REF or OUT parameter, compile period error occurs. The USING statement will be translated into three parts: capture, use methods and disposal. The use of resources will implicitly included in the TRY statement with the finally clause. This Finally clause will dispose of these resources. If you get a NULL resource, you will not call Dispose, and you will not turn back any exception. The following forms of the USING statement using (ResourceType Resource = Expression) Statement corresponds to one of two possible unfold. When ResourceType is numeric, expand is {
Resourcetype resource = express;
Try {
STATEMENT;
}
Finally {
(Idisposable) resource .dispose ();
}
} Otherwise, when ResourceType is a reference type, expand {
Resourcetype resource = express;
Try {
STATEMENT;
}
Finally {
If (resource! = null) (iDisposable) resource .dispose ();
}
} In any of the expansion, the resource variation in the inner argument is only read. The following forms of the USING statement USING (Expression) Statement has the same two possible to expand, but in this situation, ResourceType is an implicit compilation period of Expression, and the resource variable cannot be accessed in the embedded statement. And it is also invisible. When the resource is taken in the form of a regional variable declaration, it is possible to obtain a specific type of multi-resource. The following form USING statement uses (ResourceType R1 = E1, R2 = E2, ..., RN = EN) statement is completely equal to one-sequence-shaped USING statement: Using (ResourceType R1 = E1) Using (ResourceType R2 = E2 )
...
Using (ResourceType Rn = EN)
Statement