Đang chuẩn bị liên kết để tải về tài liệu:
ASP.NET 4 Unleased - p 77

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Các bộ sưu tập có tên _quotes được khai báo trong cơ thể của lớp. Bằng cách đó, bạn có thể tham khảo các trường _quotes trong xây dựng của cả hai và GetQuote sự () phương pháp. | 734 CHAPTER 17 Building Components LISTING 17.11 Quote.cs using System using System.Collections.Generic public class Quote private List string _quotes new List string public string GetQuote Random rnd new Random return _quotes rnd.Next _quotes.Count public Quote _quotes.Add All paid jobs absorb and degrade the mind -- Aristotle _quotes.Add No evil can happen to a good man either in life or after death --Plato _quotes.Add The only good is knowledge and the only evil is ignorance -Plato The collection named _quotes is declared in the body of the class. That way you can refer to the _quotes field in both the constructor and the GetQuote method. NOTE You can create static constructors by using the static keyword when declaring a constructor. A static constructor is called once before any instance constructors. Overloading Methods and Constructors When a method is overloaded a component contains two methods with exactly the same name. Many methods in .NET Framework are overloaded including String.Replace Random.Next and Page.FindControl . For example here is a list of the three overloaded versions of the Random.Next method Next Returns a random number between 0 and 2 147 483 647. Next upperbound Returns a number between 0 and the upper bound. Next lowerbound upperbound Returns a number between the lower bound and the upper bound. From the Library of Wow eBook Building Basic Components 735 Because all three methods do the same thing they all return a random number it makes sense to overload the Next method. The methods differ only in their signatures. A method signature consists of the order and type of parameters that a method accepts. For example you can t overload two methods that have exactly the same set of parameters even if the names of the parameters differ . Overloading is useful when you want to associate related methods. Overloading is also useful when you want to provide default values for parameters. For example the StoreProduct component in Listing 17.12 .

TÀI LIỆU LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.