I am trying to make this an OOP program. I wanted to use constructors so I could use the array in other classes through inheritance. I would make the actual array in the MakeArray class. The test class is an example of a class I would use the array in.
Class superClass
Protected array1D() As String
Protected array2D(,) As String
Public Sub New(ByVal array() As String)
array1D = array
End Sub
Public Sub New(ByVal array(,) As String)
array2D = array
End Sub
Public Sub New()
'intialise without a course
End Sub
End Class
Class MakeArray
Inherits superClass
Function Import1DArray() As Array
Dim fileReader As New StreamReader("1Darray.txt")
Dim lineFromFile As String = fileReader.ReadLine()
Dim counter As Integer = 0
Do
ReDim Preserve array1D(counter)
array1D(counter) = lineFromFile
lineFromFile = fileReader.ReadLine()
counter = counter + 1
Loop Until lineFromFile = ""
Return array1D
End Function
End Class
Class test
Inherits superClass
Sub test()
For i = 0 To 2 Step 1
Console.WriteLine(array1D(i))
Next
End Sub
End Class
I am quite new to OOP, so I'm not 100% sure about how it works.
Thanks!