W
e
l
c
o
m
e
: )

C#中System.ArgumentOutOfRangeException:“提供的行索引超出范围。

一、遇到的问题

报错:System.ArgumentOutOfRangeException:“提供的行索引超出范围。
如图:
在这里插入图片描述

二、解决方法

1:比如一个循环 for (int i = 1; i < list.Count; i++){}
list.Count小于0,这样就会出现索引超出范围,可以在循环上加一个判断if(list.Count > 0){}使用try-catch即可,将异常抛出。
另外一种报错:
在这里插入图片描述

附件:

提供其他解决方法:
https://blog.csdn.net/weixin_30488313/article/details/99125132
https://blog.csdn.net/weixin_44684272/article/details/106649746
https://www.thinbug.com/q/5461561

posted @ 2022-09-09 15:05  所遇所思  阅读(444)  评论(0)    收藏  举报  来源