Problem with reference

So I have this class in C#:

public class JointStruct {
	public GameObject joint { get; set; }
	public JointStruct attachedTo { get; set; }

	public JointStruct() {
		joint = null;
		attachedTo = null;
	}

	public JointStruct(GameObject go) {
		joint = go;
		attachedTo = null;
	}

	public JointStruct(GameObject go, Vector3 pos) {
		joint = go;
		joint.transform.position = pos;
		attachedTo = null;
	}

	public bool isTaken() {
		return (attachedTo == null ? false : true);
	}

	public void Attach(JointStruct attachTo) {
		attachedTo = attachTo;
		attachTo.attachedTo = this;
	}

	public void Deattach() {
		attachedTo.attachedTo = null;
		attachedTo = null;
	}

	public Vector3 getJointPosition() {
		return joint.transform.position;
	}
}

As you can see it’s quite simple. It has only two member variables and couple of simple methods. The purpose of this class is rather obvious - it creates a joint which contains an empty GameObject representing this joint and a reference to another joint this joint is attached to. If I want to attach a joint to another I call Attach method which assigns attachedTo variable in both the joint I’m attaching and the joint I’m attaching to. Deattach does the same, but it sets both attachedTo to null. Attach method actually works fine, but Deattach gives me error: “Object reference not set to an instance of an object”.

Now, I was always coding in C++ and started using C# only recently, but as far as I know attachedTo variable should contain a reference to an object it is assigned to? Or in other words, if I’m doing something with attachedTo variable, the changes should also appear in the object this variable points to or was assigned with (sorry for my English, I’m not sure if I wrote correctly what I’m trying to say). Basically saying, from what I found on the Internet, this is actually how data structures like Nodes, Trees and Stacks should be implemented in C#. In C++ I’d use pointers here, but C# seems to lack this useful feature.

Anyway, what I want to achieve here is:
Attach method should properly assign attachedTo variable to the joint I’m attaching this joint to.
And when I want to Deattach joint, I also need to tell the joint this joint is attached to that it is also no longer attached to any joint (so I need to set its attachedTo variable to null).

As I said, I wouldn’t have any problem with doing things like that in C++ (and I already did them tens of times) since I would use pointers there. But I’m not sure how to do that in C#.

I have some problems with your naming convention… “attachTo” and “attachedTo” referring to both a JointStruct and a member variable of a JointStruct makes it somewhat hard to understand!

This masks the fact that your Attach() and Detach() methods are not reciprocals of each other, which I think they should be. Did you mean this?

 public void Attach(JointStruct attachTo) {
     attachedTo = attachTo;
     attachedTo.attachedTo = this;
 }

 public void Deattach() {
     attachedTo.attachedTo = null;
     attachedTo = null;
 }