Question Odd problem...

DalexL

Active member
Joined
Jul 3, 2010
Messages
34
Programming Experience
3-5
This should be an easy one. Basically I've been getting an error saying that it can't convert System.string to System.string[]. I just want to know some details about system.string[]. I can't find any on Google because it strips out symbols.

Thanks!
 
String[] or String() is an Array of String objects.

If something expects an Array of strings, and you pass it just a String, you'll get this error. Put the String in a String array.

new String() { myStr }
 
I tried to pass the argument like this and it still gave me the same error...

VB.NET:
....., {"test", "two"})

I also tried sending a list (List of Strings) and converting it to an array and got the same error:

VB.NET:
...., ArgItems.ToArray())

Thanks though, I'll continue looking.
 
DalexL, when a sub or function accepts an array, you need to pass it in as an array:
VB.NET:
Dim StringToBePassed As String = "Something"
Dim StringAsAnArray() As String = New String() {StringToBePassed}

Call YourSub(StringAsAnArray)
'Or simpler:
Call YourSub(New String(){StringToBePassed})
If you're wanting to pass a List to the sub, I use the ToArray() extension method of the List class when passing it in, the ToArray() method returns the collection as an array for you
 
Well it turned out the problem was that it was supposed to be a multi dimensional array, I just fed it this:

func(..., {{"arg1"}, {"arg2"}}
 
Back
Top