显示:"处理NullReferenceException
未将对象引用设置到对象的实例"以下这段程序变为黄色: "string[] strContent = FileContent.Split();"以下为程序中的一段,请各住指教下:
//鼠标响应方法
private void HelloWorld_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ArrayList listContent = new ArrayList();
//将FileContent按照空格或者制表符分割成字符串数组
string[] strContent = FileContent.Split();
foreach (string str in strContent)
{
if (str != "")
{
listContent.Add(str);
}
}
string strDislpay = "";
foreach (object obj in listContent)
{
string str = obj as string;//obj转换为string类型
if (str != null)
{
strDislpay += str + System.Environment.NewLine;//????????????????????
}
MessageBox.Show(strDislpay);
}
}
未将对象引用设置到对象的实例"以下这段程序变为黄色: "string[] strContent = FileContent.Split();"以下为程序中的一段,请各住指教下:
//鼠标响应方法
private void HelloWorld_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ArrayList listContent = new ArrayList();
//将FileContent按照空格或者制表符分割成字符串数组
string[] strContent = FileContent.Split();
foreach (string str in strContent)
{
if (str != "")
{
listContent.Add(str);
}
}
string strDislpay = "";
foreach (object obj in listContent)
{
string str = obj as string;//obj转换为string类型
if (str != null)
{
strDislpay += str + System.Environment.NewLine;//????????????????????
}
MessageBox.Show(strDislpay);
}
}
private string FileContent; //文件内容
FileContent是文件内容