gpt4 book ai didi

c# - CLR 正在优化我的 forloop 变量

转载 作者:行者123 更新时间:2023-11-30 13:50:14 25 4
gpt4 key购买 nike

我正在尝试运行一个基本循环,该循环将在数据 View 网格中查找特定值。我无法弄清楚代码是怎么回事,因为 for 循环在评估其基本条件之前就退出了。

private void SearchDataViewGrid(string FileName)
{
//finds the selected entry in the DVG based on the image
for (int i = 0; i == dataPartsList.Rows.Count ; i++)
{
if(FileName == dataPartsList.Rows[i].Cells[3].Value.ToString())
{
dataPartsList.Rows[i].Selected = true;
}
}
}

程序没有崩溃,但我的“i”变量出现错误,声明它已被优化掉。尝试了一些我在网上找到的简单修复程序,但似乎没有什么可以保留它。

我已经验证我传递的字符串是正确的,并且我的“虚拟”DVG 返回包含的行数的值 14。即使我删除了 for 循环中的“if”语句,我仍然会遇到同样的错误。

最佳答案

for(init; cond; update) 中间的条件 cond 不是 until 条件而是 while 条件。

所以需要改成

 for (int i = 0; i < dataPartsList.Rows.Count ; i++)

关于c# - CLR 正在优化我的 forloop 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7046578/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com