I have a program where I am assigning several variables from within a function. When I do the assignments manually it seems to work, but if I write a helper function the assignments only seem to hold within the helper function.
foo a, b
public void Setup(int v1, int v2, int v3)
{
a = new foo(v1, v2);
a.value = v3;
b = new foo(v1, v2);
b.value = v3;
}
the above code does what I want but when I try to simplify it by creating a local method to do the assignments, it doesnt seem to work
foo var a,b
public void Setup(int v1, int v2, int v3)
{
void DoThings(foo temp, int _v1, int _v2, int _v3)
{
temp = new foo(_v1, _v2);
temp.value = _v3;
}
DoThings(a, v1, v2, v3);
DoThings(b, v1, v2, v3);
}
The above compiles properly but when I try to use a or b later in my code (in another function) I get that both are null even though I know the DoThings function ran. Is there a way to do what I am trying to accomplish or should I just do all the assignments as in the first example?
foo DoThings(...){...} a = DoThings(...); ...