The C# Programming Language phần 5

Thành viên có chứa mã thực thi chung được gọi là các thành viên chức năng của một lớp. Phần trên mô tả phương pháp, đó là các loại chính của các thành viên chức năng. Phần này mô tả các loại khác của các thành viên chức năng hỗ trợ bằng C #: xây dựng, tài sản, indexers, các sự kiện, nhà điều hành, và hàm hủy. | Classes and Objects Other Function Members Members that contain executable code are collectively known as the function members of a class. The preceding section describes methods which are the primary kind of function members. This section describes the other kinds of function members supported by C constructors properties indexers events operators and destructors. The following table shows a class called List which implements a growable list of objects. The class contains several examples of the most common kinds of function members. 1. Introduction public class List const int defaultcapacity 4 Constant object items int count Fields public List this defaultCapacity public List int capacity items new object capacity Constructors public int Count get return count public string Capacity get return set if value count value count if value object newItems new object value items 0 newItems 0 count items newItems Properties public object this int index get return items index set items index value OnListChange Indexer continues 29 1. Introduction 1. Introduction public void Add object item if count Capacity Capacity count 2 items count item count OnChanged protected virtual void OnChanged if Changed null Changed this public override bool Equals object other return Equals this other as List static bool Equals List a List b if a null return b null if b null return false for int i 0 i i if i i return false Methods public event EventHandler Changed Event public static bool operator List a List b return Equals a b public static bool operator List a List b return Equals a b Operators Constructors C supports both instance and static constructors. An instance constructor is a member that implements the actions required to initialize an instance of a class. A static constructor is a member that implements the actions required to initialize a class itself when

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
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.