c# 輸出一個數組


關於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));

 






免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM