Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 链接列表引用_C#_Linked List_Reference_Element - Fatal编程技术网

C# 链接列表引用

C# 链接列表引用,c#,linked-list,reference,element,C#,Linked List,Reference,Element,我试图在c#中的链表中插入一个元素。我得到一个invalideropertionexception,因为我认为我没有对实际链接列表节点的引用 private static LinkedList<ScoreNode> scores; private static LinkedListNode<ScoreNode> posNode; private静态链接列表分数; 私有静态LinkedListNode posNode; 当前我将posNode设置为满足特定条件的分数中的

我试图在c#中的链表中插入一个元素。我得到一个invalideropertionexception,因为我认为我没有对实际链接列表节点的引用

private static LinkedList<ScoreNode> scores;
private static LinkedListNode<ScoreNode> posNode;
private静态链接列表分数;
私有静态LinkedListNode posNode;
当前我将posNode设置为满足特定条件的分数中的元素 然后,我使用AddBefore方法在posNode之前添加一个新的LinkedListNode(ScoreNode)。 如果我是正确的,我认为我得到了异常,因为在内存中posNode之前没有存储任何内容。那么,如何从分数中的元素获取引用呢?

您是否初始化了它

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

可能值得显示用于添加新节点的代码……您需要显示将
posNode
设置为
分数元素的代码,以及显示插入的代码。如果没有这两段代码,我们将无法帮助您。他当然做到了——否则,他将得到一个空引用异常。如果没有,这将是一个
NullReferenceException
0=+1表示努力,-1表示显然不相关的答案(一个人将得到NullReferenceException)@AlexeiLevenkov我很抱歉。从我看到的代码中,我没有看到它被初始化。我不能假设任何事。