X hits on this document

810 views

0 shares

0 downloads

0 comments

272 / 396

Chapter ‎18   Unsafe code

B’s destructor A’s destructor

since destructors in an inheritance chain are called in order, from most derived to least derived.

Destructors are implemented by overriding the virtual method Finalize on System.Object. C# programs are not permitted to override this method or call it (or overrides of it) directly. For instance, the program

class A { override protected void Finalize() {}// error

public void F() { this.Finalize();// error } }

contains two errors.

The compiler behaves as if this method, and overrides of it, do not exist at all. Thus, this program:

class A { void Finalize() {}// permitted }

is valid, and the method shown hides System.Object’s Finalize method.

For a discussion of the behavior when an exception is thrown from a destructor, see §‎16.3.

Copyright Microsoft Corporation 1999-2003. All Rights Reserved.259

Document info
Document views810
Page views810
Page last viewedSun Dec 04 04:31:16 UTC 2016
Pages396
Paragraphs9401
Words133190

Comments