Lesson 2 - Practice 3 Walkthrough For each loop on an array of strings, item conversion using ToString


Hi all,

I’m going through the training material and have a question regarding the for each loop that is applied to array of strings.


As the loop goes through the array of strings it ‘write lines’ a phrase with each of the members of the array (which are all strings) each time it goes through the loop.

My question is why does the item variable which stores the string, have to be converted using .ToString to attach it to the rest of the string (why is item an object and not a string as we are talking about an array of strings, whats the point in defining the array as an array of strings in the first place?).

Sorry if this is a stupid question.



by default, the TypeArgument of the ‘for each’ activity is an object. if you’d change it to string, you won’t have to use .toString anymore.


Thanks Tiberiu for explaining. I’ve never thought of a control structure (such as a loop) as having a type I’ve always just thought of them interacting with objects (that are typed) and I didn’t even notice that the for each is typed (I still don’t really understand why it would be typed but at least that clears up why it needs the .ToString conversion).

Please excuse the overuse of the word Type :keyboard: