Hello again. This time I am having problems passing variables between methods.
Example
public static void Method1()
{
int var1 = 1;
}
public static void Method2()
{
int var2 = var1;
}
...
do you see what I am getting at?
Printable View
Hello again. This time I am having problems passing variables between methods.
Example
public static void Method1()
{
int var1 = 1;
}
public static void Method2()
{
int var2 = var1;
}
...
do you see what I am getting at?
I think you should declare the var in the class outside the void.
use parameters in your methods to pass values
Code:public static void Method1()
{
int var1 = 1;
Method2(var1);
}
public static void Method2(int inputParam)
{
int var2 = inputParam; // var2 is now 1
}
Make it an instance variable
Code:class Foo
{
int var1 = 1;
public static void Method1()
{
var1 = 1;
}
public static void Method2()
{
int var2 = var1;
}
}
I find this just depends how decisive you are, how you change your class to use a global variable.
You might be warned of the value that may have been changed while passing