Object array : Array Object « Collections « VB.Net Tutorial






Option Strict On
 Imports System
 
 MustInherit Public Class Control

    Public Sub New(top As Integer, left As Integer)
       Me.top = top
       Me.left = left
    End Sub

    Public MustOverride Sub DrawControl( )

    Protected top As Integer
    Protected left As Integer
 End Class 

 Public Class Label
    Inherits Control

    Public Sub New(top As Integer, left As Integer, contents As String)
       MyBase.New(top, left) 
       listBoxContents = contents
    End Sub

    Public Overrides Sub DrawControl( )
       Console.WriteLine("Writing string to the listbox: {0}", listBoxContents)
    End Sub 

    Private listBoxContents As String 
 End Class

 Public Class Button
    Inherits Control

    Public Sub New(top As Integer, left As Integer)
       MyBase.New(top, left)
    End Sub
    Public Overrides Sub DrawControl( )
       Console.WriteLine("Drawing a button at {0}, {1}" + ControlChars.Lf, top, left)
    End Sub 
 End Class

 Public Class Tester

    Shared Sub Main( )
       Dim winArray(3) As Control
       winArray(0) = New Label(1, 2, "A")
       winArray(1) = New Label(3, 4, "B")
       winArray(2) = New Button(5, 6)

       Dim i As Integer
       For i = 0 To 2
          winArray(i).DrawControl( )
       Next i
    End Sub 'Main

 End Class 'Tester
Writing string to the listbox: A
Writing string to the listbox: B
Drawing a button at 5, 6








8.5.Array Object
8.5.1.Object array
8.5.2.Populate Object array
8.5.3.Sort a custom object array