Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
int _i = 0;
private void Increase()
{
    _i++;

}

I want to increase start +1 it only displays 1 everytime the methods run
i want
RunFirstTime display 1 count
RunSecondTime display 2 count
and so on..
Posted
Updated 27-Jan-15 9:36am
v2
Comments
Sergey Alexandrovich Kryukov 27-Jan-15 15:29pm    
And?
—SA

1 solution

Here is the hint for you: look at the context where _i is defined and its lifetime.
Try to understand one thing: local (stack) variables live only during the call. Any local variable will be initialized to same value again and again. What are other objects, except local variables? What are their lifetimes?

By the way, don't use such names, try to follow (good) Microsoft naming conventions, and never use too short names (and try to avoid too long ones).

For very advanced understanding, not related to your exact case with the named method: what I wrote about local variables is so not in all 100% cases. The exclusions come with closures: http://en.wikipedia.org/wiki/Closure_%28computer_programming%29[^].
—SA
 
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