Click here to Skip to main content
15,913,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
C#
       public  delegate void TimeDurationPopup();
       public static int i = 0;
       protected void Page_Load(object sender, EventArgs e)
       {
           if (!IsPostBack)
           {
               TimeDurationPopup f = new TimeDurationPopup(Check);
               f();
           }
       }

       protected void btn_Click(object sender, EventArgs e)
       {
          i += 1;
       }

private void Chec()
{
    if(i==5)
    {
        //TODO my logic
    }
}

Here when I am clicking the button I am increment the I value.

If I value getting 5 I want to do some logic. But I don't want call like a method.

That method should be invoke automatically when I value getting 5. I hope I can do this problem by using delegates.

So please give me some idea.

Thanks.
Posted
Updated 29-Nov-11 0:49am
v2
Comments
RaisKazi 29-Nov-11 6:49am    
Edited: 1) Spelling Correction 2) Added "pre" tag.
Xeshan Ahmed 29-Nov-11 7:09am    
what exactly you want ??
Xeshan Ahmed 29-Nov-11 7:09am    
insufficient information provide some more information
Member 7684075 29-Nov-11 7:52am    
When i am clicking I am increment 1 to variable. When variable gets 5 some method should be invoke automatically. At the same time i dont want call the method explicitly. I hope we can use delegate and asynccallback.

Is it enough Xeshan Ahmed?

1 solution

I think we cannot have a delegate or event handler for datatypes like integer. instead you can have a function like this..

C#
Private  int i = 0;

      Public int SetGetValue
      {
         get
           {
                return i;
           }
         set
           {
               if (value == 5)
               {
                   // do your logic
               }
               else
               {
                   this.i=value;
               }
           }
      }

      protected void Page_Load(object sender, EventArgs e)
      {
          if (!IsPostBack)
          {

          }
      }

      protected void btn_Click(object sender, EventArgs e)
      {
         this.SetGetValue=(this.SetGetValue)+1;
      }


hope this helps....
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900