获取LinkedList <T>的第一个元素

use*_*571 3 c# linked-list

我是初学程序员,我在C#中遇到了这个问题.解决方案可能很简单,但这不是我的决定.

我有这个继承LinkedList的自定义类,我需要一个方法来返回第一个元素并从列表中删除它.码:

class CustomClass : LinkedList<CustomElement>
{
    public CustomElement getFirstElement(){
        //here is the problem and I don't know how to solve it
        CustomElement ce = this.First;
        this.RemoveFirst();
        return first;
    }
}
Run Code Online (Sandbox Code Playgroud)

问题是this.First返回LinkedListNode.我试过这个:

LinkedListNode<CustomElement> first = this.First;
Run Code Online (Sandbox Code Playgroud)

但是返回语句失败了,因为方法的类型是CustomElement.

O. *_*per 8

文档中所述,Value属性LinkedListNode<T>可用于访问存储在列表项中的值.因此,分配CustomElement ce = this.First.Value;.