- // Using is used as the namespace indicator
-
- Using system;
-
- Using system. Collections. Generic;
-
- Using system. text;
-
- Using system. IO;
-
-
- Namespace statement
-
- {
-
- // Specify the font class alias as F
-
- Using F = system. Drawing. Font;
-
- Class Program
-
- {
- Static void main (string [] ARGs)
-
- {
-
- // Usage of using statement for resource management
-
- Using (textwriter W = file. createtext ("E: // test.txt "))
-
- {
-
- W. writeline (@"Using statement usage: The using statement allowsProgramThe User specifies when the resource object should be released. Resource management statement function ");
- // Use an alias to instantiate an object
-
- F font =New F ("", 12 );
-
- W. writeline (font. Name. tostring () + font. Size. tostring ());
-
- }
-
-
- // The preceding using statement is equivalent to the following precompiled statement.
-
- # If debug
- Textwriter W = file. createtext ("E: // test.txt ");
-
- Try
-
- {
-
- W. writeline (@"Using statement usage: The using statement allows programmers to specify when the resource object should be released. Resource management statement function ");
-
- }
-
- Finally
-
- {
- // Standard writing method. The following statement can also be directly written as W. Dispose ()
-
- If (W! = NULL) (idisposable) W). Dispose ();
-
- }
-
- # Endif
-
-
- // You can declare an object in the using statement or declare an object before the using statement, as follows:
-
- Textreader r = file. opentext ("E: // test.txt ");
- Using (r)
-
- {
-
- String stringd = R. readtoend ();
-
- Console. writeline (stringd );
-
- }
-
- }
-
- }
-
- }
// Using is used as the namespace indicator using system; using system. collections. generic; using system. text; using system. io; namespace statement {// specify the alias of the font class as f using F = system. drawing. font; Class program {static void main (string [] ARGs) {// usage of using statement to manage resources using (textwriter W = file. createtext ("E: // test.txt") {W. writeline (@ "using statement usage: The using statement allows the programmer to specify when the resource object should be released. Has the resource management statement function "); // uses the alias to instantiate the object F font = new F (" ", 12); W. writeline (font. name. tostring () + font. size. tostring ();} // The preceding using statement is equivalent to the following precompiled statement # If debug textwriter W = file. createtext ("E: // test.txt"); try {W. writeline (@ "using statement usage: The using statement allows the programmer to specify when the resource object should be released. Has the resource management statement function ");} finally {// standard writing method. The following statement can also be directly written as W. Dispose () if (W! = NULL) (idisposable) W ). dispose () ;}# endif // you can declare an object in the using statement or declare an object before the using statement, as follows: textreader r = file. opentext ("E: // test.txt"); Using (r) {string stringd = R. readtoend (); console. writeline (stringd );}}}}
My most common problems are:
Using (sqlconnection conn = new sqlconnection (sqlhelper. sqlconnection ))
{
Dataview DV = sqlhelper. executedataset (Conn, commandtype. Text, SQL). Tables [0]. defaultview;
}