關於C#輸出一個數組最普遍的方法就是用for 循環語句寫
如:
int[] a = new int[10];
for (int i = 0; i < a.Length; i++) { a[i] = Convert.ToInt32(Console.ReadLine()); }
for (int j = 0; j <a.Length;j++)
{
Console.WriteLine(a[j]);
}
今天我在瀏覽stackoverflow的時候發現了兩個簡便的輸出數組的語句
鏈接如下
http://stackoverflow.com/questions/19146058/storing-user-input-integers-in-an-array
一個是:
foreach(var item in array) Console.WriteLine(item)
另一個更簡單的是:
Console.WriteLine(string.Join("\n", array));