Using Statement : Using Statement : File Directory Stream C# Examples


C# Examples » File Directory Stream » Using Statement »

 

Using Statement









    
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);
            }
      }
}
    
   
  
   



Output

string


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo File Directory Stream
» Using Statement