User Tools

Site Tools


using
no way to compare when less than two revisions

Differences

This shows you the differences between two versions of the page.


using [2018/04/22 11:10] (current) – created wolfgangriedmann
Line 1: Line 1:
 +The ''using'' statement is very useful if you are working with objects that need to be disposed by the garbage collector at a defined point.
 +<code>using System.IO
 +using System.Text
 +
 +function Start( ) as void                     
 +local cFileName as string
 +local aBytes as byte[]
 +                          
 +cFileName := "c:\temp\Using.txt"
 +System.Console.WriteLine("start working with" + cFileName )
 +begin using var oFile := FileStream{ cFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite } // as FileStream
 +  aBytes := Encoding.ASCII.GetBytes( "Hello world!" )
 +  oFile:Write( aBytes, 0, aBytes:Length )
 +end using                                                
 +// file is not only out of scope, but also disposed, i.e. closed
 +System.Console.WriteLine("end working with" + cFileName )
 +System.Console.Write( "press a key...." )
 +System.Console.ReadKey()
 +
 +return</code>
  
using.txt · Last modified: 2018/04/22 11:10 by wolfgangriedmann