爲什麼我得到INDEXOUTOFBOUNDS EXCEPTION ...請協助並告訴我我哪裏出錯了。我是一個新的程序員。這是代碼;C#..... IndexOutOfBoundsException
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ArrayTextFile
{
class Program
{
static void Main(string[] args)
{
string filename = "C:\\Users\\Kayloz\\Desktop\\Array.txt";
System.IO.StreamWriter W;
W = new System.IO.StreamWriter(filename);
int i;
string[] names = {"Anthony ","Paul ","Zlatan ","David ","Wayne ","Jose ","Marcus ","Daley","Inez ","Juan "};
for (i = 0; i < names.Length; i++) ;
W.Write(names[i]);
W.Close();
}
}
}
你在哪裏得到的錯誤? – Hank
'for(i = 0; i
'W.Write(names [i]);'不包含在'for'循環中,刪除循環後面的';'它應該可以工作。 – Rabban