Praise for C# 2.0: Practical Guide for Programmers 2005 phần 3

Tham khảo tài liệu 'praise for c# : practical guide for programmers 2005 phần 3', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | 36 Chapter 3 Class Members and Class Reuse 0 P 1 N 0 X 1 X5 2 5 X 3 -5 X 255 255 255 255 0 .00 1 2 5 3 -5 .23 .23 .23 .23 Output 123 -0123 000 ff 000ff FF FF .23 Declaring Destructors The garbage collector in C is an automatic memory management scheme that scans for objects that are no longer referenced and are therefore eligible for destruction. Hence memory allocated to an object is recouped automatically by a garbage collector when the object is no longer accessible or reachable . Although the garbage collector may be invoked directly using the method this practice sidesteps the heuristics and complex algorithms that are used to optimize system performance. Unless there are compelling reasons to do otherwise garbage collection is best left to the system rather than the programmer. It is safer easier and more efficient. However an object may acquire resources that are unknown to the garbage collector such as peripheral devices and database connections. These resources are the responsibility of the object itself and therefore the logic to release these resources must be Type of Format Meaning c or C d or D e or E f or F g or G n or N p or P x or X Currency Decimal Scientific with e or E 6 digits Fixed-point 12 digits General the most compact between E and F Number Percent Hexadecimal Table Numeric format types. Parameter Passing 37 implemented in a special method called a destructor. Although an object may be instantiated in any number of ways at most one destructor is declared per class. A destructor as shown here for the class Id where Id is preceded by a tilde cannot be inherited overloaded or explicitly invoked. public class Id Id release of resources Instead each destructor is invoked automatically but non-deterministically at the end of a program or by the garbage collector itself. To ensure .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.