Reputation: 21
I'm working with LinkedList in C#. All I want to do is a simple code that excludes B from the list and directly connect node A with B.Next:
A.Next = B.Next;
B.Next.Previous = A;
But got an error:
Property or indexer System.Collections.Generic.LinkedListNode<>.Next cannot be assigned to it is read only.
Is it possible to somehow get the right to assign values to Next and Previos properties? Or how can I avoid this error? Best regards.
Upvotes: 2
Views: 521
Reputation: 564471
You can just call LinkedList<T>.Remove
and pass in B
. The Remove method takes care of this for you.
Upvotes: 5