c# - Changing the property of A object affects the changing the property of B object -


i have line of code:

someclass = new someclass(); someclass b = a; a.price = 15; b.price = 20;  console.writeline(a.price); // output 20 

first create object a, , object b. object b assigned object a. when initialize property price object, can see price of object 15 , of b 20. when assign 20 price of object b, in same time changes affected on price of object a. why?

i mean happens in memory cause this?

someclass reference type (declared class someclass { ... }). a , b reference same instance of class (the 1 create new someclass(). means, points same instance (then same memory item).

to have behavior want have use value type (declared struct somestruct { ... }).


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -