简体   繁体   English

在C#中修改LinkedListNode属性

[英]Modifying LinkedListNode property in C#

I'm working with LinkedList in C#. 我正在使用C#中的LinkedList。 All I want to do is a simple code that excludes B from the list and directly connect node A with B.Next: 我只想做一个简单的代码,将B排除在列表之外,然后直接将节点A与B连接起来。

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. 属性或索引器System.Collections.Generic.LinkedListNode <>。Next不能分配给它是只读的。

Is it possible to somehow get the right to assign values to Next and Previos properties? 是否有可能以某种方式获得将值分配给Next和Previos属性的权利? Or how can I avoid this error? 或者如何避免该错误? Best regards. 最好的祝福。

You can just call LinkedList<T>.Remove and pass in B . 您可以只调用LinkedList<T>.Remove并传入B The Remove method takes care of this for you. Remove方法将为您解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM