Q:

C# generic method to affect specific object variable

I want to create a generic method that affects the variable of the object that has been passed, I really only want to send its address and generically affect it. How do I achieve something like this:
public class SomeObject() {
   float value1;
   float value2;
   float value3;
}

And in another class:
void Method1() {

   SomeObject obj;

   if(true) {
     Method2(obj.value1);
   }

   if(false) {
     Method2(obj.value2);
   }

}

void Method2(float value) {
   value++;
}

Where "value" in the second method is either obj.value1 or obj.value2 depending on the if-statement. I am sure that this question has been answered before but I don't know how to phrase my question correctly, sorry about this.

A:

You simply need to pass by reference, like this:
void Method1() {

   SomeObject obj;

   if(true) {
     Method2(ref obj.value1);
   }

   if(false) {
     Method2(ref obj.value2);
   }

}

void Method2(ref float value) {
   value++;
}

From the definition of SomeObject in the question, I am assuming that value1, value2, and value3 are fields.

