c# - Using value of a string at the left side of an if statement -


i'd use value of string @ left side of if statement. wasn't able figure out how since if statement looks inside string , doesn't pass value.

      private void buttonconf()       {            int horizotal = 40;            int vertical = 40;            label[] labelarray = new label[9];             (int = 0; < labelarray.length; i++)         {              string namestring = string.format("label_" +                                  i);              string buttonstring = string.format("this.",                                  namestring);              string id = i.tostring();                labelarray[i] = new label();                labelarray[i].size = new size(40, 40);               //labelarray[i].click += (sender, e) => labelclick(sender, e, i);                 labelarray[i].location = new point(horizotal, vertical);             if ((i == 2) || (i == 5) || (i == 9))                      {                  vertical = 40;                  horizotal = horizotal + 40;                  }              else                 vertical = vertical + 40;                 this.controls.add(labelarray[i]);                 labelarray[i].name = namestring;                 labelarray[i].text = "x";                 labelarray[i].borderstyle = borderstyle.fixed3d;                 labelarray[i].font = new font("arial black", 60);                 labelarray[i].click += new eventhandler(delegate                 {                     int click1 = 1;                     string stringo = "click" + id.tostring();                     messagebox.show(stringo);                     if (stringo == 1) { messagebox.show("true"); } // here's issue arrises                 });              }         } 

edit: hardcoded , added ==

from reading code, understand want count number of times label clicked. right?

if so, use dictionary map label id clicks counter

label[] labelarray = new label[9]; dictionary<int, int> label_click_counter = new dictionary<int, int>(9); ...     this.controls.add(labelarray[i]);     label_click_counter[i] = 0;     labelarray[i].name = namestring;     labelarray[i].text = "x";     labelarray[i].borderstyle = borderstyle.fixed3d;     labelarray[i].font = new font("arial black", 60);     labelarray[i].click += new eventhandler(delegate     {         label_click_counter[i] += 1;         if (label_click_counter[i] == 1) { messagebox.show("true"); }     }); 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -