Prev | Current Page 91 | Next

Guy Fouch?©, Trey Nash

"Accelerated VB 2008"


Also, notice that the Iterator class itself is declared Private. Non-nested classes can
only be declared as either Public or Friend, and they default to Friend. You can apply the
same access modifiers to nested classes as you can to any other member of the class. In this
case, you declare the Iterator class as Private so that external code, such as in the Main()
routine, cannot create instances of the Iterator directly. Only the Drawing class itself can
create instances of Iterator. It doesn??™t make sense for a class other than Drawing.
GetEnumerator() to be able to create an Iterator instance because this nested class acts
on its containing class.
CHAPTER 3 n CLASSES AND STRUCTURES 45
Nested classes that are declared public can be instantiated by code external to the containing
class. The notation for addressing the nested class is similar to that of namespace qualification. In
the following example, you can see how to create an instance of a nested class:
Public Class A
Public Class B
End Class
End Class
Public Class EntryPoint
Shared Sub Main()
Dim B As New A.B()
End Sub
End Class
Item Property Indexers
Indexers allow you to treat an object instance as if it were an array. This allows for a more natural
usage of objects that are meant to behave as a collection, such as instances of the Drawing
class from the previous section.


Pages:
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
wierszyki katalog stron Internet śmieszne dowcipy Jaki wybrać olej