C# 打印字符串数组列表 [英] C# Print list of string array
本文介绍了C# 打印字符串数组列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何打印字符串数组列表?我可以从 string[]
使用 Console.WriteLine
来做到这一点,但是如果我用 foreach
为一个列表这样做,它只会打印出 System.String[]
.使用 foreach
时如何编写索引?
How do I print a list of string arrays? I can do it from string[]
using Console.WriteLine
, but if I do that for a list with foreach
it just prints out System.String[]
. How do I write an index when using a foreach
?
推荐答案
最简单的方法是:使用 String.Join
The simplest way to achieve this is: using String.Join
string[] arr = new string[] { "one", "two", "three", "four" };
Console.WriteLine(String.Join("\n", arr));
希望这会有所帮助.
这篇关于C# 打印字符串数组列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文