Scrigroup - Documente si articole

Username / Parola inexistente      

Home Documente Upload Resurse Alte limbi doc  

AccessAdobe photoshopAlgoritmiAutocadBaze de dateCC sharp
CalculatoareCorel drawDot netExcelFox proFrontpageHardware
HtmlInternetJavaLinuxMatlabMs dosPascal
PhpPower pointRetele calculatoareSqlTutorialsWebdesignWindows


C sharp

+ Font mai mare | - Font mai mic


Trimite pe Messenger
Boxing and unboxing: Boxing conversions
Assignment operators
The empty statement
Relational and type testing operators
Static constructors
End points and reachability
Standard conversions


A destructor is a member that implements the actions required to destruct an instance of a class. A destructors is declared using a destructor-declaration:

~†† identifier†† (†† )††† block

A destructor-declaration may include a set of attributes17).

The identifier of a destructor-declarator must name the class in which the destructor is declared. If any other name is specified, an error occurs.

The block of a destructor declaration specifies the statements to be executed in order to destruct an instance of the class. This corresponds exactly to the block of an instance method with a void return type (ß10.5.8).

Destructors are not inherited. Thus, a class has no destructors other than the one which may be declared in it.

Since a destructor is required to have no parameters, it cannot be overloaded. Thus, a class can have, at most, one destructor.

Destructors are invoked automatically, and cannot be invoked explicitly. An instance becomes eligible for destruction when it is no longer possible for any code to use the instance. Execution of the destructor for the instance may occur at any time after the instance becomes eligible for destruction. When an instance is destructed, the destructors in its inheritance chain are called, in order, from most derived to least derived.


Describe what happens when an exception is thrown from a destructor.

The output of the example

class A


class B: A


public class Test



Bís destructor
Aís destructor

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

Implementation note

In CLR, 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
†††††† ††† // error

††††††††††††† public void F()
†††††† }

contains two errors.

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

†††††† class A
†††††† ††††††††††††††††††††††††††††††††††††††††††† // legal
†††††† }

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

Politica de confidentialitate



Vizualizari: 649
Importanta: rank

Comenteaza documentul:

Te rugam sa te autentifici sau sa iti faci cont pentru a putea comenta

Creaza cont nou

Termeni si conditii de utilizare | Contact
© SCRIGROUP 2022 . All rights reserved

Distribuie URL

Adauga cod HTML in site