【发布时间】:2012-06-11 11:41:11
【问题描述】:
我是一名初级程序员,我在 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。
【问题讨论】:
-
如果您想在读取第一个元素时移除(出列)第一个元素,请考虑使用队列。
-
不知道为什么会有这么多反对意见。通过谷歌立即找到它,它包含我解决问题所需的确切信息。
标签: c# linked-list