0

I am doing something wrong as I am getting a resulting string of "System.String[]" when I attempt to String.Join the following:

Dim MyList As String()

' DB select here returns a comma delimited column value
' using dr As DataRow

MyList = dr("someColumnn").trim.trim(",").split(",") 
' Debug watch on MyList at this point shows:
'   Name: MyLIst, Value: {Length=1}, Type: Object {String()}
' And when I expand that entry I see:
'   Name: (0), Value: "Item1", Type: String

' Then in the Razor page:
List: @String.Join(" | ", MyList)
' Displays: 
'   List: System.String[]

' EDIT: This is the workaround I am doing for now:
Dim L As New List(Of String)
For Each Item As String In MyLIst
    L.Add(Item)
Next

' In the razor page:
@String.Join(", ", L) 

What am I doing wrong?

Drew
  • 4,215
  • 3
  • 26
  • 40
  • Can't replicate, and the only different I see is `List: @String` vs `@String` – A Friend May 16 '18 at 15:04
  • Thanks. I was hoping I was doing something wrong rather than dealing with a system unicorn. FYI - The "List:" portion of the example is just illustrating that there is some Razor content before inserting the @String.Join(", ", L) content into the razor page. – Drew May 16 '18 at 15:19
  • 1
    I think it must be something to do with the data reader, since `Type: Object {String()}` means the string array has been wrapped. – A Friend May 16 '18 at 15:23
  • 1
    Because `MyList` has an item of type of `String[]`, hence when you trying to join on each string in that array, you only get `System.String[]`. This is a debugging issue, set a breakpoint on `List: @String.Join(" | ", MyList)` and inspect `MyList`, expand it and check each object in that array, guaranteed that one of those items are `System.String[]` as a string representation. – Trevor May 16 '18 at 17:25

0 Answers0