我有一個字符串數組,如下所示: 如何將它們中的每一個寫入控制檯? 下面是從我的C#程序代碼:從下面的代碼,我有所有的貓寫入控制檯從C中讀取數組#
using (RegistryKey ic = clsidKey.OpenSubKey("Implemented Categories"))
{
string[] cats = ic.GetSubKeyNames();
}
我有一個字符串數組,如下所示: 如何將它們中的每一個寫入控制檯? 下面是從我的C#程序代碼:從下面的代碼,我有所有的貓寫入控制檯從C中讀取數組#
using (RegistryKey ic = clsidKey.OpenSubKey("Implemented Categories"))
{
string[] cats = ic.GetSubKeyNames();
}
難道你不這樣做呢?
foreach (string cat in cats) {
Console.WriteLine(cat);
}
試試這個:
foreach(string cat in cats)
{
Console.WriteLine(cat);
}
或者甚至更具體:
foreach(string cat in cats)
{
Console.Out.WriteLine(cat);
}
Linq中的風格
Array.ForEach(cats, Console.WriteLine);
你也可以使用Array.ForEach(cats,System.Console.WriteLine);因爲System.Console.WriteLine滿足操作
編輯以反映它。 – 2009-10-02 19:49:12
Console.Writeline已經增加了斷行,所以你不需要成\ n除非你想添加間隔線。 – 2009-10-02 18:21:50
爲什麼「\ n」? WriteLine已經處理新行... – 2009-10-02 18:22:23
您不需要「\ n」,因爲您正在使用WriteLine而不是Write,並且最好使用Environment.NewLine。 – 2009-10-02 18:23:21