Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
đó là khuyến cáo rằng bạn cô lập tất cả các nguồn lực của bạn trong một hội đồng riêng biệt để họ có thể được trao đổi một cách dễ dàng với một nền văn hóa khác nhau mà không ảnh hưởng đến mã của bạn. Hội đồng chia sẻ đưa chúng ta đến khái niệm về đặt tên lắp ráp. | CHAPTER 4 CLASSES AND STRUCTURES 63 System.Console.WriteLine Circle.Draw End Sub End Class Public Class Drawing Private Shapes As ArrayList Public Sub New Shapes New ArrayList End Sub Public ReadOnly Property Count As Integer Get Return Shapes.Count End Get End Property Default Public ReadOnly Property Item ByVal Index As Integer As GeometricShape Get Return CType Shapes Index GeometricShape End Get End Property Public Sub Add ByVal Shape As GeometricShape Shapes.Add Shape End Sub End Class Public Class EntryPoint Shared Sub Main Dim Rectangle As Rectangle New Rectangle Dim Circle As Circle New Circle Dim Drawing As Drawing New Drawing Dim i As Integer 0 Drawing.Add Rectangle Drawing.Add Circle For i 0 To Drawing.Count - 1 Step 1 Dim Shape As GeometricShape Drawing i Shape.Draw Next End Sub End Class 64 CHAPTER 4 CLASSES AND STRUCTURES As shown you can access the elements of the Drawing object in the Main routine as if they were inside a normal array. Also since this indexer only has a Get accessor it is read-only. Keep in mind that if the collection holds onto references to objects the client code can still change the state of the contained object through that reference. But since the indexer is readonly the client code cannot swap out the object reference at a specific index with a reference to a completely different object. One difference is worth noting between a real array and the indexer. You cannot pass the results of calling an indexer on an object as a ByRef parameter to a method as you can do with a real array. This is similar to the same restriction placed on properties. Partial Classes Partial classes are a new addition to VB. So far you ve seen how to define classes in one single file. Until now it was impossible to split the definition of a class across multiple files. At first such a convenience may not seem worthwhile. After all if a class has become so large that the file is hard to manage that may be an indication of poor design. But arguably the