返回System.String []而不是数组 [英] System.String[] returned instead of array
本文介绍了返回System.String []而不是数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试返回一个字符串数组,但返回测试;
仅给出"System.String []"作为输出.如果我通过test []进行迭代,则所有值均正确填写.我在做什么错了?
I'm trying to return an array of strings but return test;
only gives "System.String[]" as output. If I iterate through test[] all values are filled in correctly. What am I doing wrong?
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.
I'm using MS Visual C# 2010.
推荐答案
在数组上调用 .ToString()
将返回"System.String []".如果要显示数组中的每个值,请对其进行迭代.
Calling .ToString()
on an array will return "System.String[]". If you want to display each value in the array, you have iterate over it.
例如:
foreach (var value in test)
{
Console.WriteLine(value);
}
或者,正如@Oded指出的那样,您可以使用 String.Join .
Or, as @Oded pointed out, you can use String.Join.
Console.WriteLine(String.Join(Environment.NewLine, stringArray));
这篇关于返回System.String []而不是数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文