LinkedList in c# xamarin

I have a linked list which contains views. I want to assign the last view element in the list to another view variable.

This is what I did :-

private readonly LinkedList<View> bufferedViews = new LinkedList<View>();
View myView = bufferedViews.RemoveLast ();

also this:-

if (bufferIndex + 1 > sideBufferSize)
{
    releaseView(bufferedViews.RemoveFirst());
}

But I get an error saying :-

Cannot convert from void to Android.Views.View
Jon Skeet
people
quotationmark

This isn't a Xamarin issue. Your code is just broken. Both RemoveFirst and RemoveLast are void methods - they don't return the first/last elements, they just remove them.

You'll need to use the First and Last properties, then remove the first and last values afterwards - assuming you actually want to remove the value. (It's not clear from the code whether you really do.)

You could always write extension methods to do what you want though:

public static T FetchAndRemoveFirst<T>(this LinkedList<T> list)
{
    T first = list.First.Value;
    list.RemoveFirst();
    return first;
}

public static T FetchAndRemoveLast<T>(this LinkedList<T> list)
{
    T last = list.Last.Value;
    list.RemoveLast();
    return last;
}

people

See more on this question at Stackoverflow