本文介绍了C#索引超出范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

我正在检查两个datagridviews之间的值,如果其中之一不存在该值,则需要插入到value中.我的代码工作正常,但是当我获得不存在的值时,我得到了索引超出范围错误.

我知道错误的含义,但我不知道如何处理.在执行代码之前,我需要检查索引是否超出范围.

有人可以告诉我如何检查索引是否超出范围吗? ,毫无用处,绝对无用..."绝对不会使任何人想要帮助您.

其次,是的,买一本书.从编码的基础开始,因为很明显您还没有这样做.从这个问题来看,我只能假设您已经做了类似的事情:

  int  i =  0 ;

同时()
{
  如果(dataGridView1.Rows(i)...)
  {

  }
  i ++;
} 



这根本不是正确的方法.

几乎所有控制列表的内容都将具有Count属性.告诉您...等待中...该列表中的项目数.那么,如何:

  int  i =  0 ;

同时(i <  dataGridView1.Rows.Count)
{
  // 做某事

  i ++;
} 



当然,这是从基本编码类开始的解决方案.有很多其他方法可以做到,如果您不了解它们,那就买本书或上课.




Hi!

I am checking values between two datagridviews and if the value does not exist in one of them I need to insert to value. My code works fine but when I get to the value that does not exist I get an Index out of range error.

I know what the error means but I do not know how to handle it. I need to check if the index is out of range before executing my code.

Can someone please tell me how to check if the Index is out of range?

解决方案




这篇关于C#索引超出范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 17:06
查看更多