c# - Global variable won't work in searching in one function -


i made program gets info in textbox1 , textbox2 after pressing button1. if type in textbox3 , if wrote there same textbox1 ,after pressing button2 puts textbox2's text in label2.text.

but problem won't put textbox2.text label2.text. why?

here's code:

public partial class form1 : form {     public form1()     {         initializecomponent();     }     ozv[] = new ozv[5];     int = 0;     private void button1_click(object sender, eventargs e)     {         a[i] = new ozv();         a[i].name = textbox1.text;         a[i].id = int.parse(textbox2.text);         i++;     }      private void button2_click(object sender, eventargs e)     {         (int j = 0; j < 5; j++)         {             a[j] = new ozv();             if (a[j].name == textbox3.text)             {                 label2.text = a[j].id.tostring();             }         }     } } 

and here's class made:

class ozv { public string name; public int id; }

remove line:

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

you erasing saved, why not getting result.

also, check a[j] instance defined:

if (a[j] != null) && a[j].name == textbox3.text) 

you can break; after find first matching occurence, exit loop earlier.

note 1: should try going step-by-step code, , looking @ variable states. debug stuff that.

note 2: should consider using list<ozv> can iterate on without having handle nulls.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -