RCIX
RCIX

Reputation: 39427

Keeping track of a value type without making a copy, or "Are there ref fields"?

Is it possible to maintain a reference to a value type so that when changes are made to it my code can see them?

Example: i am building a 2D camera for XNA and i want to be able to give it a reference to an arbitrary vector2 so that i don't have to have a special interface or something that everything has to implement. Is this possible?

Upvotes: 0

Views: 92

Answers (1)

Reed Copsey
Reed Copsey

Reputation: 564393

You cannot do this. ValueTypes are not stores on the heap in .NET, so the only (practical) way to keep a reference is to put them inside of a reference type.

Usually you just keep a reference to the object containing or managing the Vector2, so that the Camera could read it as needed.

Upvotes: 1

Related Questions