views:

45

answers:

3

Hi,

I'm trying to write a function that returns an Array that I can pass into a String.Format:

Public Function ToArray() As Array
    Dim vals As New ArrayList()
    vals.Add(Me("district"))
    vals.Add(Me("county"))
    vals.Add(Me("route"))
    vals.Add(Me("section"))
    vals.Add(Me("beg_logmile"))
    vals.Add(Me("end_logmile"))
    vals.Add(Me("date_logged"))
    vals.Add(Me("year_installed").year())
    vals.Add(Me("document"))
    Return vals.ToArray()
End Function

Public Overrides Function toString() As String
    Return String.Format("{0} {1} {2} {3} {4:f3} {5:f3} {6} {7} {8}", Me.ToArray())
End Function

The above does not work. I've converted it to just String.Format("{0}", Me.ToArray()) and it tells me that I've got a System.Object[]

I haven't been able to find an answer yet on Google or SO, so any help would be appreciated!

+2  A: 

Change your function declaration to this:

Public Function ToArray() As Object()

The ToString() overload you are using expects an array of objects, not an instance of the Array class.

David M
Ah! Perfect! Thanks!
Wayne Werner
+2  A: 

Your function should look like this:

Public Function ToArray() As Object()
    Return New Object() {Me("district"), Me("county"), Me("route"), ... ,Me("document") }
End Function
Joel Coehoorn
A: 

Try making your definition:

Public Overrides Function toString() As String()

bechbd