First, let's define a node:
LinkedListNode<int> node = new LinkedListNode<int>(43);
You'll notice that the properties node.List
, node.Next
and node.Previous
are all get
only. Now let's add the node to a LinkedList
:
LinkedList<int> linkedlist = new LinkedList<int>();
linkedlist.AddFirst(node);
At this point, the property node.List
will have change to contain a reference to linkedlist
. Similarly, if other nodes are added to the LinkedList
, the Next
and Previous
properties will be updated to reflect the structure of the linked list, even though these properties do not expose a public set
accessor.
How is this behavior implemented?
I know how to do it using internal
, but is there a better way? For example, suppose I have a single assembly that contains many types, not just LinkedList
and LinkedListNode
. By making the setters for the node properties List
, Previous
and Next
, I am exposing these setters to the whole assembly, which is undesired.