Lecture overview -- Keyboard shortcut: 'u'  Previous page: Example: Filestreams -- Keyboard shortcut: 'p'  Next page: More FileStream Examples -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home  Page 7 : 40
Object-oriented Programming in C#
Input and Output Classes
The using control structure

The using control structure is helpful when we do IO programming



using (type variable = initializer)
  body

The syntax of the using statement C#

  • Semantics

    • In the scope of using, bind variable to the value of initializer

    • The type must implement the interface IDisposable

    • Execute body with the established name binding

    • At the end of body do variable.Dispose

      • The Dispose methods in the subclasses of Stream call Close

 

/user/normark/oop-csharp-1/sources/notes/includes/using-equivalenceThe control structure 'using' defined by 'try-finally'.


/user/normark/oop-csharp-1/sources/c-sharp/io/filestream-ex/2/write-prog.csThe simple write-program programmed with 'using'.


/user/normark/oop-csharp-1/sources/c-sharp/io/filestream-ex/2/read-prog.csThe simple read-program programmed with 'using'.