I have code that generates a List<string[]> variable but can’t quite figure out how to get it to display in a text box properly.
List<string[]> test = parseCSV();
for (int i = 0; i < test.Count; i++)
{
Console.WriteLine("i = {0}",i);
Console.WriteLine("test[i] = {0}", test[i]);
nameList.Text = test[i].ToString() + "\n" + nameList.Text;
}
When I output test[i] to the console it displays the string information correctly, but when I output test[i] to a text box I get:
System.String[]
System.String[]
System.String[]
System.String[]
System.String[]
System.String[]
Can anyone tell me what I’m doing wrong?
This is a common misconception with
ToStringthat shows up in a variety of situations. It is not a magical formatting wizard, even if primitive types appear to work “as you expect”. ToString simply provides a reasonable representation of the data at hand.In the case of array data, it would be obnoxious and likely incorrect for .Net to output the entire array for every ToString call (which the debugger makes heavy usage of). Imagine a 3D array of strings that is 60x60x10. I would hate to have to wait on that to get rendered simply because I put my mouse over an array in the debugger.
In this case you could use
String.Join: