C# Object reference to another object's property

SonnyListon

Say I have an object's property pointing to different objects during its lifetime.

MyClassInstance.MyProperty = MyOtherObject1;

Later in the application I get this:

MyClassInstance.MyProperty = MyOtherObject2;

And so on. My understanding is that MyOtherObject1 and MyOtherObject2 will be pointing to the same address in memory, which I want to avoid. How can I make sure MyOtherObject1 and MyotherObject2 are 2 completely different entities?

Andreas Tsiapis

If MyOtherObject1 and MyOtherObject2 are different objects, making the MyClassInstance.MyProperty equal to them, will not result in these 2 being the same.

MyClassInstance.MyProperty = MyOtherObject1;

This means any changes to MyClassInstance.MyProperty will change MyOtherObject1, as they effectively point to the same memory space.

MyClassInstance.MyProperty = MyOtherObject2;

This means that MyProperty now points to the same memory space as MyOtherObject2. Changes to MyProperty will leave MyOtherProperty1 unaffected.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Reference an object's property by a string (or integer) that contains specified part of the object's name - C#

From Dev

Any way to assign a variable (not an object property) another variable's value by reference in JavaScript?

From Dev

Reference behavior for property of an object

From Dev

Can C++ reference refer to another object?

From Dev

How to update an object's property from another object ngrx

From Dev

Getting Value (Description) of an object's property in another object

From Dev

Creating a reference to another object

From Dev

Swift: taking reference of object's property with ampersand (&) causing compiler error

From Dev

Javascript create reference to an object property?

From Dev

Store a reference to a property of an object in a variable

From Dev

Reference error "object property is not defined"

From Dev

Store a reference to a property of an object in a variable

From Dev

Reference object property through variable

From Dev

"Object reference not set to an instance of an object" on navigation property

From Dev

How do I change the value of an object's attribute that's a reference to another object's attribute?

From Dev

Reference object instance inside of another object

From Dev

Java reference to selected values of object to another object?

From Dev

Copy object reference to another observable

From Dev

Remove reference to another object in javascript

From Dev

Apply IQueryable reference on another object

From Dev

Remove reference to another object in javascript

From Dev

base class is a reference to another object

From Dev

_.difference checks for object reference or checks property by property?

From Dev

Issue with ng-model changing another object's property values

From Dev

How to store a reference of an object inside of another class c++?

From Dev

A way to pass c++ object to another object's method in cython

From Dev

A way to pass c++ object to another object's method in cython

From Dev

Object reference, c#

From Dev

unwanted object property changed when changing another object property c#

Related Related

  1. 1

    Reference an object's property by a string (or integer) that contains specified part of the object's name - C#

  2. 2

    Any way to assign a variable (not an object property) another variable's value by reference in JavaScript?

  3. 3

    Reference behavior for property of an object

  4. 4

    Can C++ reference refer to another object?

  5. 5

    How to update an object's property from another object ngrx

  6. 6

    Getting Value (Description) of an object's property in another object

  7. 7

    Creating a reference to another object

  8. 8

    Swift: taking reference of object's property with ampersand (&) causing compiler error

  9. 9

    Javascript create reference to an object property?

  10. 10

    Store a reference to a property of an object in a variable

  11. 11

    Reference error "object property is not defined"

  12. 12

    Store a reference to a property of an object in a variable

  13. 13

    Reference object property through variable

  14. 14

    "Object reference not set to an instance of an object" on navigation property

  15. 15

    How do I change the value of an object's attribute that's a reference to another object's attribute?

  16. 16

    Reference object instance inside of another object

  17. 17

    Java reference to selected values of object to another object?

  18. 18

    Copy object reference to another observable

  19. 19

    Remove reference to another object in javascript

  20. 20

    Apply IQueryable reference on another object

  21. 21

    Remove reference to another object in javascript

  22. 22

    base class is a reference to another object

  23. 23

    _.difference checks for object reference or checks property by property?

  24. 24

    Issue with ng-model changing another object's property values

  25. 25

    How to store a reference of an object inside of another class c++?

  26. 26

    A way to pass c++ object to another object's method in cython

  27. 27

    A way to pass c++ object to another object's method in cython

  28. 28

    Object reference, c#

  29. 29

    unwanted object property changed when changing another object property c#

HotTag

Archive