// Use the members of rw.
}
finally
{
// Always call Dispose(), error or not.
rw.Dispose();
}
}
While this is a fine example of defensive programming, the truth of the matter is that few devel-
opers are thrilled by the prospects of wrapping each and every disposable type within a try/finally
block just to ensure the Dispose() method is called. To achieve the same result in a much less obtru-
sive manner, C# supports a special bit of syntax that looks like this:
static void Main(string[] args)
{
Console.WriteLine("***** Fun with Dispose *****\n");
Do'stlaringiz bilan baham: |