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.
As described in the documentation, the
Valueproperty ofLinkedListNode<T>can be used to access the value stored in the list item. Therefore, assignCustomElement ce = this.First.Value;.