链表参考

发布于 2024-12-27 17:53:10 字数 387 浏览 6 评论 0原文

我正在尝试将一个元素插入到 C# 中的链接列表中。我收到 invaliderOperationException 因为我认为我没有对实际链接列表节点的引用。

private static LinkedList<ScoreNode> scores;
private static LinkedListNode<ScoreNode> posNode;

当前我将posNode设置为scores中满足一定条件的元素 然后我使用 AddBefore 方法在 posNode 之前添加一个新的 LinkedListNode(ScoreNode)。 所以如果我是正确的,我认为我得到了异常,因为内存中 posNode 之前没有存储任何内容。那么我怎样才能从分数中的元素获取参考呢?

I am trying to insert an element into a linked list in c#. I get an invaliderOperationException because I think I do not have a reference to the actually linked-list-node.

private static LinkedList<ScoreNode> scores;
private static LinkedListNode<ScoreNode> posNode;

Current I set posNode to the element in scores that satisfies a certain condition
then I use the AddBefore method to add a new LinkedListNode(ScoreNode) before posNode.
So if I am correct, I think that I get the exception because there is nothing stored before posNode in memory. So how could i get a reference from an element in scores?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瞄了个咪的 2025-01-03 17:53:10

你初始化了吗?

private static LinkedList<ScoreNode> scores = new LinkedList<ScoreNode>();

Did you initialize it?

private static LinkedList<ScoreNode> scores = new LinkedList<ScoreNode>();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文