我是一名初学者程序员,我在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;
}
}
问题是this.First
返回了LinkedListNode。我尝试过以下方法:
LinkedListNode<CustomElement> first = this.First;
但是返回语句失败了,因为方法的类型是CustomElement
。