gpt4 book ai didi

c# - 获取 LinkedList 的第一个元素

转载 作者:行者123 更新时间:2023-11-30 14:00:22 28 4
gpt4 key购买 nike

我是一名初级程序员,我在 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

最佳答案

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

关于c# - 获取 LinkedList<T> 的第一个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10979366/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com