Global variable won't work in searching in one function

有些话、适合烂在心里 提交于 2019-12-02 07:58:48

Remove this line:

for (int j = 0; j < 5; j++)
    {
--->    a[j] = new ozv();
        if (a[j].name == textBox3.Text)

You are erasing what you just saved, this is why you are not getting any result.

Also, check that you a[j] instance is defined:

if (a[j] != null) && a[j].name == textBox3.Text)

You can also break; after you find the first matching occurence, to exit the loop earlier.

Note 1: you should try going step-by-step into your code, and looking at the variable states. This would really help you debug stuff like that.

Note 2: you should consider using a List<ozv> so that you can just iterate over it without having to handle nulls.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!