0

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!

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

Comments

2

Your function should look like this:

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

Comments

0

Try making your definition:

Public Overrides Function toString() As String()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.