Vernan
Vernan

Reputation: 21

Modifying LinkedListNode property in C#

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

Answers (1)

Reed Copsey
Reed Copsey

Reputation: 564471

You can just call LinkedList<T>.Remove and pass in B. The Remove method takes care of this for you.

Upvotes: 5

Related Questions