ref and value types

Dec 2 2005 3:30 AM
Hi,

Yesterday I made a Blog about value and reference types and how they act. A string is also a reference type but does it act like an reference type?

some code:

Person p = new Person( "Jan" );
Persoon refP = p;
p.FirstName = "Kevin";
Console.WriteLine("My First person = " + p.FirstName);
Console.WriteLine("My reference= " + refP .FirstName);

Person is a class that is also an reference type. Now my code with a string:

string test;
test =
"myFirstTest";
string test2 = test;
test2 =
"mySecondTest";
MessageBox.Show("test = " + test + " en test2 = " + test2);

my output is not the output that a expect from a referencetype? How come, I don't know, could it be because I don't make a instance with the keyword new??


This is maybe a simple question but actually I don't know the answer. Can someone figure this out for me!

thanks K

Answers (3)