爲什麼我越來越: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相同的錯誤,但有不同的信息... –