I had read an article http://www.albahari.com/valuevsreftypes.aspx
As per this, int
is a value type and form
is an example of reference type.
Point myPoint = new Point (0, 0); // a new value-type variable
Form myForm = new Form(); // a new reference-type variable
string mystringval="test";
Test (myPoint, myForm); // Test is a method defined below
void Test (Point p, Form f)
{
p.X = 100; // No effect on MyPoint since p is a copy
f.Text = "Hello, World!"; // This will change myForm’s caption since
// myForm and f point to the same object
f = null; // No effect on myForm
}
So instead of form variable myform
, if I pass a string value to the function test, will it also change the original value which I already declared outside?
Also what is the benefit of keeping the string as reference type, if, anyhow the value will be saved in stack and only the reference will be stored in heap?