What statements can use the using management?
Analysis: scarce resources require using management.
is the using release a managed or unmanaged resource?
So what are managed and unmanaged resources?
managed resources are resources that are allocated and freed by the CLR, typically managed memory, while unmanaged resources are resources that are allocated and freed by the system. In general, the new object in the CLR or the allocation of an array does not need to be manually disposed of within, such as the handle resource in Windows, is often required to be released manually, such as fonts, brushes, DC, and all window kernel objects (handles) are unmanaged resources such as file handles, socket handles, form handles ... Too much.The memory that the new object occupies is a managed resource.
Parsing: unmanaged ,C # apps hosted into the . NET Framework. But he can release unmanaged resources.
Two. The role of the using statement
Parse: as a keyword, using can import namespaces
As a C # statement, the using can free the memory resources occupied by the object, with the following basic syntax
using (SqlConnection con=new SqlConnection ("")) { // database operation code }
Three. The nature of the using statement
Parsing: (Since the using can release the object, is it possible to use a using to restrict all objects before it?) )
Not so;
Using an object that can be actively freed requires the implementation of the Idisable interface
Now that we've implemented the idisable excuse, there's no need to use using all of them, we're only using qualified objects that have a significant impact on system performance, and other objects can be handed off to the Akira recovery processor.
Four. The Dispose method automatically calls Close ()
For a type to be managed by using , the type or parent class must implement the IDisposable interface.
using (SqlConnection con=new SqlConnection) { // essentially automatically calls the Dispose method }
1.close () and Dispose () difference?
Parse: Close() just closes the connection, but the channel is not destroyed,andDispose () not only closes the connection, but also destroys the channel.
Using a using-free resource