错误:startindex不能小于零。 [英] Error: startindex cannot be less than zero.

查看:1404
本文介绍了错误:startindex不能小于零。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

i got "StartIndex cannot be less than zero.
Parameter name: startIndex" 

在数据库中保存更改后,它会在此行引发错误。 />

After save changes in database it throws an error on this line.

string pHOF = a.HOF.ToString().Substring(Convert.ToString(a.HOF).Length - 3);



请帮助我非常紧急。

谢谢你。



我的尝试:



我是新的在MVC中并且不知道如何调试。


Please Help me its very urgent.
Thank you.

What I have tried:

I'm new in MVC and don't know how to debug.

推荐答案

@OriginalGriff是对的,Substring方法执行该参数。在这种情况下,它会将参数视为起始索引。尝试调试代码以查看HOF中的内容。根据此处发布的内容,HOF的长度必须为3或更多。



以下示例将输出: cde 因为5 - 3 = 2 ,它将从位置2(0,1,2,3,4)开始读取,即c。

@OriginalGriff is right, the Substring method do that one parameter. That case it will treat the parameter as start index. Try debug the code to see what in the HOF. The length of HOF must be 3 or more according to what posted here.

Example below will output: cde because 5 - 3 = 2, it will start to read from position 2 (0,1,2,3,4) which is c.
object HOF = "abcde";
		
string pHOF = HOF.ToString().Substring(Convert.ToString(HOF).Length - 3);





以下示例将输出: StartIndex不能小于零。参数名称:startIndex 因为2 - 3 = -1,startIndex必须为0或更多。



Example below will output: StartIndex cannot be less than zero. Parameter name: startIndex because 2 - 3 = -1, the startIndex must be 0 or more.

object HOF = "ab";
		
string pHOF = HOF.ToString().Substring(Convert.ToString(HOF).Length - 3);



如上所述,substring方法缺少起始索引。它应该是substring(startinxex,endindex)。在你的场景中,它会像.Substring(0,a.HOF.Length -3)



c - Google搜索 [ ^ ]


As the error mentioned, the substring method is missing the start index. It should be substring(startinxex, endindex). In your scenario, it would be something like .Substring(0, a.HOF.Length -3)

c - Google Search[^]


检查您的原始输入:如果< pre> Convert.ToString(a.HOF)< / pre> 的长度为2或者更少,那么子字符串的起始索引将是负数,你将得到这个错误。



使用调试器,并确切地检查<$ c $中的内容c> a.HOF 在执行该代码之前。
Check your original input: if the length of <pre>Convert.ToString(a.HOF)</pre> is two or less, then the start index for the substring will be negative and you will get this error.

Use the debugger, and check exactly what is in a.HOF before you execute that code.


这篇关于错误:startindex不能小于零。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆