No. It won't.
That's because all parameters passed in C# unless otherwise specified are passed by value, not by reference.
To explain, think about this:
public void TimesTwo(int x)
{
x = x + x;
}
...
int value = 666;
TimesTwo(value);
Console.WriteLine(value);
If value was passed by reference (i.e. the x inside the method was the same variable as value outside the method) then the console would print "1332".
But ... what if I called it like this:
TimesTwo(666);
Console.WriteLine(666);
What would you expect the console to show? "1332" or "666"?
Fairly obviously, we want the console to print "666" because otherwise constants are no longer constant, and the rest of our code is going to become impossible to follow!
So C# passes by value, not reference: a copy of the variable content is made and is passed to the method. Because TimesTwo is changing the copy, it doesn't affect the outside world, and constants remain the same.
The same thing happens with strings: a copy of the string is passed to the method, and your code "modifies" that copy, and the copy is discarded when the method exits.
Except ... with strings it's even worse, because strings are immutable: once you create a string in C#, it can't be changed at all - every time you try, you create a new string, and they both then exist side by side.
If you want to pass a value back, you can .. but you have to specify that when you both create and use the method:
public void Pin1Contact(out string pinXsign, out double pinXvolts)
{
pinXsign = pin1_Sign; pinXvolts = pin1_Volts;
}
dcps.Pin1Contact(out led.pin1_Sign, out led.pin1_Volts);
This tells the system to return parameters by reference, rather than by value.
YOu can also use the
ref
keyword instead, and the system will let you access the current value in the method as well:
public void Pin1Contact(ref string pinXsign, ref double pinXvolts)
{
pinXsign += pin1_Sign; pinXvolts += pin1_Volts;
}
dcps.Pin1Contact(ref led.pin1_Sign, ref led.pin1_Volts);