List of objects returns System.String[] instead of actual message


I’m adding objects to a list with invoke method and it’s method Add.
The output from iterating the list is “System.String” instead of the actual information that has been added.

Why is this?
The list have been initlialized as: list = new list(of Object)
The variables added in the object (v1, v2, v3) is declared as Strings.


How are you outputting the values? sortedList.ToString will return System.Object[]

The correct way would be to use String.Join() or a For each loop.
If it requires it to be a String array, then use .Select()
String.Join(",",sortedList.Select(Function(x) x.ToString))

Does that solve it?




I’m using a regular for each loop like the screen shot belowfor outputting.
It needs to be a list and not array since the size may vary.

I don’t understand how I should use the examples that you provided. Could you explain this to me again please? :slight_smile:


Since it’s a list of objects, you probably need to convert item to a string, like item.ToString

Your method should work as long as you output it as a String, but to use my examples, you can simply place it into a Log Message, Write Line, etc. (no For each loop needed as it outputs all items in the list into one string. This works for all enumerables, arrays, and lists.

Thank you for the response!
I tried both scenarios.
First I tried the for each loop and converting item to String, but the same output System.String was shown.

The other ways with the “Joins” just gave the same result in one line.

I was not allowed to convert the sortedList to String since “System.Collections.Generic.List(of Object)”

I think you are creating a list of arrays. So v1, v2, and v3 must be array or list type variables. Is this correct? If this is what you need, then you will need to run a loop inside of a loop for each variable. If that is not what you need, then you will need to change v1, v2, and v3 to a different type (not an array or list).

To output each variable array in the list, you can do this:

for each item in sortedList
    for each item2 in item

or a one liner would be like this:
String.Join(",",sortedList.Select(Function(x) String.Join(",",x.Select(Function(y) y.ToString)))

If you still having trouble, you might upload your code, and I can examine it better.



No, actually v1 v2 and v3 are Strings that each have been fetched from four different emails.
I want to save v1, v2 and v3 into an object for each of the four emails, that is why I am collecting them in the SortedList,

I have attached some of my code. It would be much appreciated if you would like to have a look. :slight_smile: Main.xaml (11.4 KB)

Thank you for the support!

I think I found the problem. You are adding an Object array to the list and not each individual object or string.

newObj is an array that = {v1,v2,v3}, therefore you are adding that array to the list. I think what you are trying to do is add each item in newObj, correct? Try using a For each, like this:
to add each individual item.

Also, I recommend using a String instead of Object for the List, since the Regex will always return a string anyway.

Let me know if this helps.


Sorry for my late reply!
Yes,I’m trying to save the information from v1, v2 and v3 in newObj, that is correct.

Your solution works except that the loop seems to add and save over the other items in the list. So only the last item in the list is saved, not all four of them.

Maybe you need a counter for the index to +1 or something like that?


That’s weird. Ok, I will test it when I get a chance to make sure it’s working correctly. You shouldn’t need a counter with the Add method.

1 Like

Thank you! I managed to fix it on my own. I appriciate your help! :slight_smile:

Best regards Klara

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.