Professional ASP.NET 1.0 Special Edition- P29

Professional Special Edition- P29:Those of us who are Microsoft developers can't help but notice that .NET has received a fair amount of visibility over the last year or so. This is quite surprising considering that for most of this period, .NET has been in its early infancy and beta versions. I can't remember any unreleased product that has caused this much interest among developers. And that's really an important point, because ignoring all the hype and press, .NET really is a product for developers, providing a great foundation for building all types of applications | Implementing the Add Method The Add method allows a new Product to be added to the collection Public Sub Add Item as Product If Item Is Nothing Then throw new ArgumentException Product cannot be null End If Item End Sub This method throws an ArgumentException if a Null item parameter is passed. If the parameter is not Null the Code property of the passed Product is used as the key for the Product in the contained Hashtable. Depending on our requirements we could perform additional business logic validation here and throw additional exceptions. Implementing the Remove Method The Remove method removes a Product from the collection. The implementation of the method simply calls the Remove method of the Hashtable Public Sub Remove Item as Product End Sub Implementing the Item Property The Item Property allows a Product to be retrieved from or added to the collection using the product code Public Default Property Item Code as String as Product Get Item CType _products Code Product End Get Set Add Value End Set End Property The implementation of the Set accessor calls the Add method in order to add the new product to the internal Hashtable. The process is implemented in away so that any business logic in the Add method such as the Null check is neither duplicated nor missed. Implementing the GetEnumerator Method So that our collection class can be used with the statements in Visual and C our collection class must have a method called GetEnumerator. Although not strictly necessary we also implement the IEnumerable interface using the Visual Implements keyword. This is good practice and requires very little work Public Class ProductCollection Implements IEnumerable Implement an enumerator for the products Public Function GetEnumerator As IEnumerator Implements GetEnumerator End Function End Class The GetEnumerator method has to return an .

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
173    308    2    27-06-2024
Đã 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.