我收到一个空引用异常错误,它与子字符串函数或 LastIndex 函数有关。我很困惑为什么
String[] m_SessionNames;
String[] filenames; //Filenames already initialized in code
int Index = 0;
foreach (String name in filenames)
{
MessageBox.Show(filenames[index]) //Works, Displays a string that includes a '\'
m_SessionNames[Index] = filenames[Index].Substring((filenames[Index].LastIndexOf('\\') > 0) ? filenames[Index].LastIndexOf('\\') + 1 : 0);
Index++;
}