public void main()
{
string test = "testing";
ChangeVal(test);
Console.WriteLine(test);
}
private void ChangeVal(string test)
{
test = "in child";
}
If String is a class. and i pass string as a parameter to a function. change the value of that string in function. But in main function it shows the previous values. It will print testing value.
when i created Foo class which has 2 member variable integer and string. when i passed the object of the class as parameter and change value of the member variable in function. It will give updated value in the main function
public class Foo
{
public string test = "testing";
public int i = 5;
}
public void main()
{
Foo obj=new Foo();
Console.WriteLine(obj.test);
ChangeVal(obj);
Console.WriteLine(obj.test);
}
private void ChangeVal(Foo obj)
{
obj.test = "in child";
obj.i = 5;
}
If string is the class. It will update the value of the variable. May string is the sequence of Unicode character that's why it doesn't update the value in 1st case. Can any body will explain this in detail.
ChangeValmethod do:obj = null, see if you get the change in the main method,