c# - Counter--; Help me understand -


application, have textblock , 2 buttons, text displayed textblock clicking on button (the text of q.txt read line line, on hundred lines):

public class qwork {    public static int counter = 0;     public static string getq()     {         var qfile = new list<string>();          string pathfile = "q.txt";         uri uri = new uri(pathfile, urikind.relative);         streamresourceinfo sri = application.getresourcestream(uri);         using (streamreader sr = new streamreader(sri.stream))         {             string line = "";             while (line != null)             {                 line = sr.readline();                 if (line != null)                     qfile.add(line);  // add list             }             return qfile[counter];         }     } } 

buttons event handler:

    private void rightbutton_click(object sender, routedeventargs e)//next text     {         qtextblock.text = qwork.getq();         qwork.counter++;     }      private void leftbutton_click(object sender, routedeventargs e)//previous text     {         qtextblock.text = qwork.getq();         qwork.counter --;     } 

problem: when click leftbutton, first still shows following line, after previous. tell me please, how can fix it.

thanks!

maybe can you

int counter = 0; list<string> qs = null;  private void loadqs() {     qs = new list<string>();     qs.add("aaa");     qs.add("bbb");     qs.add("ccc"); }  private string getq(bool increase) {     if (increase)         counter++;     else         counter--;      if (counter >= qs.count)         counter = 0;     else if (counter <= 0)         counter = qs.count;      string q = qs[counter];      return q; } 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -