unity3d - C# - How can I insure a static method effects its parameters directly and not just instances? -


i have 2 static methods, , 1 want do, , can't figure out what's wrong other. more specifically, method_a seems not make instance of parameter , operates on same variable created in main, whereas b appears operate on instance.

public static method_a(vector2[] in, int n) {      for(int = 0; < in.length; i++)      {           in[i].x = n;           in[i].y = n;      } }  public static method_b(vector2 in, int n) {      in.x = n;      in.y = n; } 

and main:

// works, , changes values directly in "test" vector2[] test = meshfilter.uv; method_a(test, n); meshfilter.uv = test;  // fails, doesn't affect test vector2 test = meshfilter.uv[i]; method_b(test, n); meshfilter.uv[i] = test;  // fails, doesn't affect test vector2[] t = meshfilter.uv (...for loop...){ vector2 test = t[i]; method_b(test, n); t[i] = test;} meshfilter.uv = t; 

i method b work on original variable, not on instance... can ensure this?

please let me know if additional details required.

thank you.

this how value types work in c#. if want operate on original struct, need pass reference.

public static method_b(ref vector2 in, int n) {     in.x = n;     in.y = n; } 

also, need specify it's been passed reference @ call site.

method_b(ref test, n); 

this not needed array, because arrays reference types. passed reference [1], method_a working on original array.

[1] pedantic, array variables (e.g. vector2[] arr array variable) references arrays. value of arr passed value default, , since reference array, has effect of passing array reference.