I extremely get counfused about types of reference. I searched and saw that the string type is a reference type. Is not ?
My problem is :
I copied a string variable to another and I changed the value of first one however the second one has still the same value. I did not understand this issue. Even though type of string is a reference type, the second one does not change. Also I tried the boxing method but I could not obtain the result.
I read this article In C#, why is String a reference type that behaves like a value type?, however I still get counfused.
And this is my code:
string my_text1 = "My text 1";
string my_text2 = my_text1;
my_text1 = "My text 2";
Console.WriteLine("First text --> " + my_text1); // It prints My text 2
Console.WriteLine("Second text -->" + my_text2); // It prints My text 1(I want it prints "My text 2" too)
string text_1 = "Example 1";
object text_2 = text_1;
text_1 = "Example 2";
Console.WriteLine("First example --> " + text_1); // It prints Example 2
Console.WriteLine("Second example -->" + text_2);// It prints Example 1