Hopefully, this doesn't get marked as a duplicate. I've read a ton of different threads, but still not sure the best way to accomplish this.
Typically, I would just use global variables. From all the reading, it definitely appears that this shouldn't be done unless absolutely necessary. I'm sure that isn't the case for me. So I'm trying to follow best practice.
Let's just say I have something similar below.
public class myClass
{
private void myMethod
{
}
}
How do I declare a static variable within myMethod? It seems I can only use static by delcaring it
private static myVariable
But I cannot declare this from within my method.
If I declare this within myClass, then it is still of global scope and I believe it is limited to file scope. I could be wrong there. Is there not a way to limit the scope of the variable to myMethod?
Basically, I have a counter in that method that needs to retain its value throughout the duration of the program.