I have read the Difference between a Value Type and a Reference Type, in this article, the author is saying:
Because reference types represent the address of the variable rather than the data itself, assigning a reference variable to another doesn't copy the data. Instead it creates a second copy of the reference, which refers to the same location of the heap as the original value
Based on the above quote, I expected the following code which will assigning a reference variable to another, doesn't copy the data but it is indeed copying the data as well. Would you please help me to understand this?
Class1 i1 = new Class1();
i1.Name = "Name1";
Class1 i2 = i1;
//i2.Name is "Name1"
For i2
I expected it refers to the same location of the heap as the i1
value that is right, but based on the article the data should not be copied. Also my question is not deserve to be marked as duplicate because I know about the difference between value and reference type, I just need some clarification about reference types and what's the usage of deep copy/clone/shallow, if we can simply use assignment?