TAILIEUCHUNG - DATA STRUCTURES AND ALGORITHMS USING VISUAL BASIC.NET phần 1

MoveNext () gia tăng chỉ số và kiểm tra để xem liệu kết thúc của mảng đã được đạt tới: Công Chức năng MoveNext () Như Boolean _ Thực hiện chỉ số + = 1 Nếu chỉ số = Sau đó, Quay trở lại False Else Return True End Nếu Cuối Chức năng | 32 COLLECTIONS MoveNext increments the index and checks to see whether the end of the array has been reached Public Function MoveNext As Boolean _ Implements index 1 If index Then Return False Else Return True End If End Function The method returns False if the array is out of elements and True otherwise. The Current property is implemented as a read-only property since its only purpose is to return the current element of the array Public ReadOnly Property Current As Object _ Implements Get Return ccol index End Get End Property The Reset method is implemented because the Enumerator class requires it. All it does is set the index back to -1 when appropriate. Now that we have all the code in place we can use the CEnumerator class to enumerate our custom collection of elements. We went to all the trouble to develop the class so that we can use a For Each statement to loop through the elements in the collection. When we use the For Each the enumerator for the collection is called and is used to enumerate the underlying array. One problem we ll see with this implementation is that every element of the array gets displayed even those elements that don t have a value. This will make your collection list look somewhat messy consequently you might want to decrease the initial capacity of the list. Let s put all this together and look at an example that demonstrates how to use the CEnumerator class by creating a list of names and displaying them A Collection Class Implementation Using Arrays 33 using a For Each statement Module Modulel Public Class CCollection Implements IEnumerable Protected pCapacity As Integer 8 Protected pArr 8 As Object Protected pIndex As Integer Protected pCount As Integer Public Sub New pIndex 0 pCount 0 End Sub ReadOnly Property Count Get Return pCount End Get End Property Public Sub Add ByVal item As Object If Then pCapacity 8 ReDim Preserve pArr .

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.