Option Strict On
Imports System
Public Class MyItemList
Private strings(255) As String
Private ctr As Integer = 0
Public Sub New(ByVal ParamArray initialStrings( ) As String)
Dim s As String
For Each s In initialStrings
strings(ctr) = s
ctr += 1
Next
End Sub
Public Sub Add(ByVal theString As String)
If ctr >= Strings.Length Then
Else
Strings(ctr) = theString
ctr += 1
End If
End Sub
Default Public Property Item(ByVal index As Integer) As String
Get
If index < 0 Or index >= strings.Length Then
Else
Return strings(index)
End If
End Get
Set(ByVal Value As String)
If index >= ctr Then
Else
strings(index) = Value
End If
End Set
End Property
Public Function Count( ) As Integer
Return ctr
End Function
End Class
Public Class Tester
Public Shared Sub Main( )
Dim lbt As New MyItemList("Hello", "World")
Dim i As Integer
Console.WriteLine("After creation...")
For i = 0 To lbt.Count - 1
Console.WriteLine("lbt({0}): {1}", i, lbt(i))
Next
lbt.Add("W")
lbt.Add("I")
lbt.Add("J")
lbt.Add("t")
Console.WriteLine("After adding strings...")
For i = 0 To lbt.Count - 1
Console.WriteLine("lbt({0}): {1}", i, lbt(i))
Next
Dim subst As String = "e"
lbt(1) = subst
Console.WriteLine("After editing strings...")
For i = 0 To lbt.Count - 1
Console.WriteLine("lbt({0}): {1}", i, lbt(i))
Next
End Sub
End Class
|