我编写了以下代码将文件名存储在字符串数组中:
string[] fileStore;
private void button1_Click(object sender, EventArgs e)
{
DirectoryInfo dir1 = new DirectoryInfo(@"D:\data\");
FileInfo[] files = dir1.GetFiles("*.txt", SearchOption.AllDirectories);
foreach (FileInfo f in files)
{
int a = 0;
string ss;
ss = f.Name;
try
{
fileStore[a] = ss.ToString();
a++;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
但是这段代码给出了以下异常:
你调用的对象是空的。