长度不能小于零。参数名称:长度 [英] Length cannot be less than zero. Parameter name: length
本文介绍了长度不能小于零。参数名称:长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
protected void asd_Click(object sender, EventArgs e)
{
if (Common.Common.ApplicationInformation.LoggedInUser.RGroupIds != null)
{
string Documentid = string.Empty;
string GroupIds = string.Empty;
string DocumentIds = string.Empty;
string ContactIds = string.Empty;
//----------------
if (Session["ReportDocumentIDs"].ToString() != null)
{
DocumentIds = Session["ReportDocumentIDs"].ToString();
Documentid = DocumentIds.Substring(0, DocumentIds.LastIndexOf(','));
}
else
{
Documentid = null;
}
推荐答案
请阅读文档 [ ^ ]。这是因为
Please read the documentation[^]. It happens because
MSDN写道:
String.LastIndexOf
方法报告从零开始的索引位置此实例中最后一次出现的指定Unicode字符或字符串。 如果在此实例中找不到字符或字符串,则该方法返回-1。
String.LastIndexOf
method reports the zero-based index position of the last occurrence of a specified Unicode character or string within this instance. The method returns -1 if the character or string is not found in this instance.
所以,你不能返回以零开头并以-1结尾的子串;)
So, you can not return substring which starts with zero and ends with -1 ;)
长度不能小于零。
Documentid = DocumentIds.Substring(0,DocumentIds.LastIndexOf(','));
如果你传递的文件没有',';
DocumentIds.LastIndexOf(',')这将返回-1;
然后Documentid = DocumentIds.Substring(0,-1);抛出异常..
尝试处理它..如果您需要更多帮助,请告诉我..
Length cannot be less than zero.
Documentid = DocumentIds.Substring(0, DocumentIds.LastIndexOf(','));
This exception will occur if you are passing a DocumentIds without a ',' ;
DocumentIds.LastIndexOf(',') this will return -1;
then Documentid = DocumentIds.Substring(0, -1); throws exception..
Try to handle it..If you need more help let me know..
这篇关于长度不能小于零。参数名称:长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文