Exemple #1
0
 private static void TraditionalUsingStatement()
 {
     using (var r = new AResource())
     {
         r.UseIt();
     }  // r.Dispose is called
 }
Exemple #2
0
 private static void NewMultipleUsingDeclarations()
 {
     using var r1 = new AResource();
     using var r2 = new AResource();
     r1.UseIt();
     r2.UseIt();
 }
 private static void UsingStatement()
 {
     using (var r = new AResource())
     {
         r.Use();
     }
 }
Exemple #4
0
        }  // resource is disposed here

        private static void UsingDeclarationWithScope()
        {
            {
                using var r1 = new AResource();
                r1.UseIt();
            }  // r1 is disposed here!
            Console.WriteLine("r1 is already disposed");
        }
Exemple #5
0
 private static void TraditionalMultipleUsingStatements2()
 {
     using (var r1 = new AResource())
         using (var r2 = new AResource())
         {
             r1.UseIt();
             r2.UseIt();
         }
 }
Exemple #6
0
        private static void TraditionalUsingStatementExpanded()
        {
            var r = new AResource();

            try
            {
                r.UseIt();
            }
            finally
            {
                r.Dispose();
            }
        }
Exemple #7
0
 private static void NewWithUsingDeclaration()
 {
     using var r = new AResource();
     r.UseIt();
 }
 private static void UsingDeclaration()
 {
     using var r = new AResource();
     r.Use();
 }