public void MethodSample1(Itest variable)
{
variable.TestString = "some sample data";
Itest var1 = variable;
Console.WriteLine(variable.TestString);
MethodSample2(variable);
Console.WriteLine(variable.TestString);
Console.WriteLine(var1.TestString);
}
public void MethodSample2(Itest variable)
{
variable.TestString = "testdata";
}
public interface Itest
{
string TestString { get; set; }
}
Expected both the console output lines print "some sample data" but it seems that TestString
is being overwritten with the new value? is it not like "by default in C# all the values are passed by value?".
In short, how to preserve the value of "TestString" in MethodSample1
?
(I ran into this problem because all my projects are based upon a single interface)
Even after preserving the value, it does reflect! strange!