如果不做出任何决定?

发布于 2024-09-19 01:32:53 字数 365 浏览 2 评论 0原文

看这个:

foreach(Object Item in comboBox1.Items)
{
    if (Convert.ToString(Item) == Convert.ToString(dsGirasol.Tables["DatosGirasol"].Rows[contador][0]))
    {
        repetido = true;
        break;
    }
    else
    {
        repetido = false;
    }
}​

请注意,两个可能的输出都有一个消息框。然而,当我运行这个时,什么也没有出现,其余的代码继续运行...

编辑:添加了周围的循环!

Look at this:

foreach(Object Item in comboBox1.Items)
{
    if (Convert.ToString(Item) == Convert.ToString(dsGirasol.Tables["DatosGirasol"].Rows[contador][0]))
    {
        repetido = true;
        break;
    }
    else
    {
        repetido = false;
    }
}​

Note that both of the possible outputs have a messagebox. However when I run this, nothing appears at all, and the rest of the code continues to run...

EDIT: Added the surrounding loop!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情未る 2024-09-26 01:32:54

为什么你想要 break 在那里?试试这个:

if (Convert.ToString(Item) == Convert.ToString(dsMaiz.Tables["DatosMaiz"].Rows[contador][0]))
{
    repetido = true;
    MessageBox.Show("Encontre uno igual");
}
else
{
    repetido = false;
    MessageBox.Show("Encontre uno diferente");
}

Why do you want the break there for? Try this:

if (Convert.ToString(Item) == Convert.ToString(dsMaiz.Tables["DatosMaiz"].Rows[contador][0]))
{
    repetido = true;
    MessageBox.Show("Encontre uno igual");
}
else
{
    repetido = false;
    MessageBox.Show("Encontre uno diferente");
}
一场春暖 2024-09-26 01:32:54

在评估相等性之前,尝试评估条件的左侧和右侧部分。
我只能想象它一定抛出了一个被默默捕获的异常。
这将帮助您调试问题。

例如:

var left = Convert.ToString(Item);
var right = Convert.ToString(dsMaiz.Tables["DatosMaiz"].Rows[contador][0]);
if (left == right)
{
    ...
}
else
{
  ...
}

编辑:
现在我看到您正在使用循环,回到基础知识,循环是否正在运行?
低技术调试,检查组合框中是否有一些项目,并且您正在引用您想要的组合:)

Try evaluating the left and right parts of the condition before you evaluate the equality.
I can only imagine that it must be throwing an exception that is silently caught.
This will help you debug the issue.

eg:

var left = Convert.ToString(Item);
var right = Convert.ToString(dsMaiz.Tables["DatosMaiz"].Rows[contador][0]);
if (left == right)
{
    ...
}
else
{
  ...
}

EDIT:
Now that I see you are using a loop, go back to basics, is the loop even running?
Low tech debugging, check that there are some Items in the combobox and that you are referencing the combo you intended :)

记忆之渊 2024-09-26 01:32:54

好吧,这很奇怪,我设法通过将每个循环放在一个单独的方法上来解决这个问题,现在它可以工作了,无论如何感谢您的帮助!

Ok this is strange, I managed to solve the problem by puting each loop on a separate method, and now it works, thanks for the help anyways!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文