我是初学程序员,我在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.
| 归档时间: |
|
| 查看次数: |
6528 次 |
| 最近记录: |