为什么我越来越:C#编译器错误与子串
Index and length must refer to a location within the string.
Parameter name: length
当我编译此代码: http://pastebin.com/CW4EcCM8
它的某些部分:
public string findFileEnding(string file)
{
int index1 = file.IndexOf('.');
file = file.Substring(index1, file.Length);
return file;
}
感谢;)
有没有支票,索引1是> -1(这还出现了。在字符串中)。如果你做一个子字符串W /索引:-1它也会引发错误... – Rikon
不是你的问题的答案,但更可靠的方式来找到文件扩展名是使用路径类:http:// msdn。 microsoft.com/en-us/library/system.io.path.aspx –
@Rikon相同的错误,但有不同的信息... –