System.String 返回而不是数组
我正在尝试返回一个字符串数组但return test;
只给出“System.String []”作为输出。 如果我遍历test [],则所有值都会正确填充。 我究竟做错了什么?
public static String[] ReturnTheStrings() { FillTheArray(); String[] test = new String[178]; for (int i = 0; i < 178; i++) { if ((Class7.Method4(strings[i])) == "decoding wrong") { test[i] = strings[i+1]; //System.Console.WriteLine("Non-encoded value"); } else { test[i] = Class7.Method4(strings[i+1]); //System.Console.WriteLine("Encoded value"); } } return test; }
我正在使用MS Visual C#2010。
在数组上调用.ToString()
将返回“System.String []”。 如果要显示数组中的每个值,则必须对其进行迭代。
例如:
foreach (var value in test) { Console.WriteLine(value); }
或者,正如@Oded指出的那样,你可以使用String.Join 。
Console.WriteLine(String.Join(Environment.NewLine, stringArray));