Prev | Current Page 92 | Next

Guy Fouch?©, Trey Nash

"Accelerated VB 2008"

Indexers in VB are implemented via an Item default property,
and may not be Private or Shared.
Conceptually, the indexer is similar to a method in that it can take a parameter when
used, and you can apply many of the same modifiers to the indexer as you can to a method.
However, it also behaves like a property, as you define the accessors with a similar syntax. Following
the parameter list in the indexer declaration is the code block for the indexer, which is
just like a property code block in its syntax. The main difference is that the accessors for the
indexer can access the parameter passed, whereas the accessors of a property don??™t have userdefined
parameters. Let??™s add an indexer to the Drawing object and see how you can use it:
Imports System.Collections
Public MustInherit Class GeometricShape
Public MustOverride Sub Draw()
End Class
Public Class Rectangle
Inherits GeometricShape
Public Overrides Sub Draw()
System.Console.WriteLine("Rectangle.Draw")
End Sub
End Class
Public Class Circle
Inherits GeometricShape
CHAPTER 3 n CLASSES AND STRUCTURES 46
Public Overrides Sub Draw()
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.


Pages:
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
fenomenalne mieszkania do wynajęcia warszawa magazyny w warszawie śmieszne dowcipy sufit podwieszany katalog stron