A
Andi Wolf
Hello,
as i belived c# will always transfer the variables as by vale if not marked
with a ref infront of the decleration.
By using the folowing code there seams to be (at least for me) a strange
behavior:
namespace xyz
{
public class Class1
{
public static double[] Real(double[] yValue, bool invers)
{
yValue = test(yValue);
return (yValue);
}
private static double[] test(double[] data)
{
data[1] = 11;
return (new double[] { 3, 4, 5 });
}
}
}
Main Programm:
using xyz;
....
double[] d = new double[] { 1, 0, 3, 0};
double[] d1 = new double[] { 1, 2, 3, 4};
d1 = Class1.Real(d, false);
....
If I watch the variables d and d1 by the debugger i get the folowing
results: d1 := { 3, 4, 5 } and d := { 1, 11, 3, 0}. I would not have
expexted, that the d[1] value would have been changed to 11, because the d
parameter wasn' t given by the ref. In my opinion the d value shouln't have
been changed at all?
Any ideas why this happens? Im using VS2005 SP1 and I think there are no
parameters in VS which can be changed to get this reaktion of the code?
regards Andi
as i belived c# will always transfer the variables as by vale if not marked
with a ref infront of the decleration.
By using the folowing code there seams to be (at least for me) a strange
behavior:
namespace xyz
{
public class Class1
{
public static double[] Real(double[] yValue, bool invers)
{
yValue = test(yValue);
return (yValue);
}
private static double[] test(double[] data)
{
data[1] = 11;
return (new double[] { 3, 4, 5 });
}
}
}
Main Programm:
using xyz;
....
double[] d = new double[] { 1, 0, 3, 0};
double[] d1 = new double[] { 1, 2, 3, 4};
d1 = Class1.Real(d, false);
....
If I watch the variables d and d1 by the debugger i get the folowing
results: d1 := { 3, 4, 5 } and d := { 1, 11, 3, 0}. I would not have
expexted, that the d[1] value would have been changed to 11, because the d
parameter wasn' t given by the ref. In my opinion the d value shouln't have
been changed at all?
Any ideas why this happens? Im using VS2005 SP1 and I think there are no
parameters in VS which can be changed to get this reaktion of the code?
regards Andi