Brad White wrote:
> The reason that we have to use 'using' in C# > is to make finalization deterministic. > [...] > In Delphi that is called Free.
No. That's not right. The closest thing to Delphi's Free in C# is IDisposable. The following code samples are more or less equivalent:
Delphi:
foo = TFoo.Create; foo.Bar; foo.Free;
C#
foo = new Foo(); foo.Bar(); foo.Dispose();
Neither one is robust. Better would be (again, these are sort of similar in what they do):
Delphi:
foo = TFoo.Create; try foo.Bar; finally foo.Free; end;
C#
using (var foo = new Foo()) { foo.Bar(); }
Like Rudy said, C#'s using is closer to Delphi's try/finally (though not the same).
-- Craig Stuntz __ Vertex Systems Corp. __ Columbus, OH Delphi/InterBase Weblog : http://blogs.teamb.com/craigstuntz/