Two functions of the using statement:
1) using can import namespaces
2) The using can release the memory resources occupied by the object.
The code is as follows:
using (SqlConnection con=new SqlConnection (constring)) { // database operation code }
The using statement allows the user to define a range and dispose of the object at the end of the range. A database connection object is defined in the using statement, and when the program executes at the end of the using statement, the CLR immediately releases the object by calling the object's Dispose () method.
is the using release a managed or unmanaged resource?
Analytical:
unmanaged, C # apps are hosted into the. NET Framework. But he can release unmanaged resources.
Using substance
During the program compilation phase, the compiler automatically builds the using statement into a try-finally statement and calls the object's Dispose method in the finally block to clean up the resource. Therefore, the using statement is equivalent to the try-finally statement
What is the difference between close () and Dispose ()?
Close () Just closes the connection, but the channel is not destroyed, and Dispose () not only shuts down the connection, but also destroys the channel.
Use of the Using keyword