Create object inside the using statement : Using Statement « File Directory Stream « C# / CSharp Tutorial






using System; 
using System.IO; 
 
class MainClass { 
  public static void Main() { 
     
    using(StreamReader sr2 = new StreamReader("test.txt")) { 
      Console.WriteLine(sr2.ReadLine()); 
      sr2.Close(); 
    } 
 
  } 
}
124.23








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