I am trying to return a List(Of T) from a function, as follows:
Public Class Observers
Private Structure Observer
Dim Name As String
Dim ObsLat As Double
Dim ObsLong As Double
Dim ObsElev As Integer
Dim UTCOffset As Int16
Dim ObsDst As Boolean
Dim ObsEmail As String
End Structure
Public Function loadObservers() As List(Of Observer) 'Error here. Observer is highlighted
Dim sr As New StreamReader("Observers.txt")
Dim obslist As New List(Of Observer)
Dim obsdata As New Observer
If File.Exists("Observers.txt") Then
Dim s() As String
Do
s = Split(sr.ReadLine(), ",")
obsdata.Name = s(0).Trim
obsdata.ObsLat = CDbl(s(1))
obsdata.ObsLong = CDbl(s(2))
obsdata.ObsElev = CInt(s(3))
obsdata.UTCOffset = CShort(s(4))
obsdata.ObsDst = CBool(s(5))
obsdata.ObsEmail = s(6).Trim
obslist.Add(obsdata)
Loop Until sr.Peek = -1
End If
loadObservers = obslist
End Function
End Class
I get an error in the Function Declaration. List(Of Observer). Observer is highlighted, and the errors read:
error BC36666: 'SatTransNew.Observers.Public Function loadObservers() As System.Collections.Generic.List(Of Observers.Observer)' is not accessible in this context because the return type is not accessible.
error BC30508: 'loadObservers' cannot expose type 'Observer' in namespace 'SatTransNew' through class 'Observers'.
I tried moving the Dim obslist As New List(Of Observer) outside the function, but it didn't help.
Is it possible to Return a List(Of T), or should I go with an array?
Edit: I just tried making the Structure declaration Publlic, and it now compiles. Is that the answer? I was going to keep that private, though thinking about it, I can't see why it matters.\
This post has been edited by lar3ry: 20 November 2012 - 01:44 PM

New Topic/Question
Reply




MultiQuote







|