Using Statement: using DIRECTIVE, not using statement : Using Statement « File Directory Stream « C# / CSharp Tutorial






using System;              
using System.IO; //using DIRECTIVE, not using statement

class MainClass
{
   static void Main()
   {
      using (TextWriter tw = File.CreateText("test.txt"))// using statement 
      {
         tw.WriteLine("string");
      }

      using (TextReader tr = File.OpenText("test.txt"))
      {
         string str;
         while (null != (str = tr.ReadLine()))
            Console.WriteLine(str);
      }
   }
}
string








15.33.Using Statement
15.33.1.Use object inside using statement
15.33.2.Create object inside the using statement
15.33.3.Using Statement: using DIRECTIVE, not using statement
15.33.4.Use FileStream inside a using statement
15.33.5.Dispose a StreamWriter by using 'using'
15.33.6.Using statement to deal with multiple resources
15.33.7.Nested using statement