© { JSL }
79
Text Box: Local Resources
Local Resources
Folded Corner:
·deterministic finalisation via finally...
wis exception safe, but...
wis repetitive and doesn't scale
wis complex and fails to abstract
TextReader reader = null;
try {  
    FileInfo source = new FileInfo(filename);
    int length = (int)source.Length;
    char[] contents = new char[length];
    reader = source.OpenText();
    reader.Read(contents, 0, length);
    ...
}
...
finally {
    if (reader != null) {
        reader.Close();
    }       
}