S
Siegfried Heintze
On line 5 of the program below I get the error message in the subject line.
(1) How may I correct it?
(2) How may I enhance my Arr class to work with a foreach statement?
(3) In C++ I can pass integer constants (like 1990) as template (generic)
parameters. Can I do that in VB.NET or must I use the constructor for that?
Thanks,
Siegfried
Module Module1
Class Arr(Of T)
Private data() As T
Public Sub New(ByVal n As Integer)
data = New T(n)
End Sub
Default Public Property Item(ByVal index As Integer) As T
Get
Return data(index - 1990)
End Get
Set(ByVal Value As T)
data(index - 1990) = Value
End Set
End Property
End Class
Declare Function _getch Lib "msvcrt.dll" () As Integer
Sub Main(ByVal args() As String)
Dim out As System.IO.TextWriter = System.Console.Out
Dim arr1 As Arr(Of Double) = New Arr(Of Double)(3)
Dim arr2 As Arr(Of String) = New Arr(Of String)(3)
arr1(1990) = 1.3
arr1(1991) = 4.5
arr1(1992) = 3
arr2(1990) = "A"
arr2(1991) = "B"
arr2(1992) = "C"
Dim ii As Integer
For ii = 1990 To 1992
out.WriteLine(arr1(ii) + ":" + arr2(ii))
Next
out.Write("hit return to continue: ")
_getch()
End Sub
End Module
(1) How may I correct it?
(2) How may I enhance my Arr class to work with a foreach statement?
(3) In C++ I can pass integer constants (like 1990) as template (generic)
parameters. Can I do that in VB.NET or must I use the constructor for that?
Thanks,
Siegfried
Module Module1
Class Arr(Of T)
Private data() As T
Public Sub New(ByVal n As Integer)
data = New T(n)
End Sub
Default Public Property Item(ByVal index As Integer) As T
Get
Return data(index - 1990)
End Get
Set(ByVal Value As T)
data(index - 1990) = Value
End Set
End Property
End Class
Declare Function _getch Lib "msvcrt.dll" () As Integer
Sub Main(ByVal args() As String)
Dim out As System.IO.TextWriter = System.Console.Out
Dim arr1 As Arr(Of Double) = New Arr(Of Double)(3)
Dim arr2 As Arr(Of String) = New Arr(Of String)(3)
arr1(1990) = 1.3
arr1(1991) = 4.5
arr1(1992) = 3
arr2(1990) = "A"
arr2(1991) = "B"
arr2(1992) = "C"
Dim ii As Integer
For ii = 1990 To 1992
out.WriteLine(arr1(ii) + ":" + arr2(ii))
Next
out.Write("hit return to continue: ")
_getch()
End Sub
End Module