why cant i put all my variables outside the methods? whats going to happen?
i trigger every method each time, and each of the methods are simply reused?
Not sure if I understand your question completely so please tell me if I got something wrong.
If your variables are used by multiple methods and they need to store the changes between method calls e.g. a balance variable for a bank account, then you should put these variables outside of the any methods.
If your variables are used across all methods then they will keep their values unless you specifically change them.
public int num = 0;
public void addto()
{
num++;
}
public void removefrom()
{
num--;
}
In the code above number will retain its value between calls, if i called add twice and remove once, then the value would be 1;
public void addto()
{
num = 1
}
public void removefrom()
{
num--;
}
in this bit of code the add function sets the variable therefore calling add twice and remove once would give the value of 0.
As for putting all of your variables outside of methods, it does make your code a lot harder to read through and debug.
Hope some of this will help you.
-Matt