我有問題陣列在C#無法獲得C#陣列工作
裏面我上課的時候我在
>>> public static void Main(string[] args) {
Console.WriteLine (new string[] { "I", "Like", "π" });
}
鍵入console說
System.String[]
相反的陣列我通過。
我想要做的是適合一個數組到一個像這樣的方法:
>>> public static void Main(string[] args) {
DoSomething ({ "I", "Like", "π" });
}
>>> public static int DoSomething(string[] array) {
for (int i = 0; i > array.Length; i++) {
Console.WriteLine (array [i]);
}
}
我得到一個錯誤說
Unexpected symbol '{' on 'DoSomething ({ "I", "Like", "π" });'
如何解決這些錯誤?
因爲你不能打印'字符串[]'(這是字符串數組)元素一樣,直接說。 – Prajwal
而你的方法不返回一個int,使該方法無效! –
string []與System.String []是一樣的。 「string」只是「String」的別名 –