Reputation: 305
I'm a beginner programmer and I have this problem in C#. The solution is probably easy, but that's not for me to decide.
I have this custom class that inherits LinkedList and I need a method to return first element and remove it from list. Code:
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;
}
}
Problem is that this.First
returns LinkedListNode. I tried this:
LinkedListNode<CustomElement> first = this.First;
But then the return statement fails, because type of method is CustomElement
.
Upvotes: 6
Views: 10786
Reputation: 20780
As described in the documentation, the Value
property of LinkedListNode<T>
can be used to access the value stored in the list item. Therefore, assign CustomElement ce = this.First.Value;
.
Upvotes: 12