[英]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
This isn't a Xamarin issue. 这不是Xamarin问题。 Your code is just broken. 您的代码已损坏。 Both RemoveFirst
and RemoveLast
are void
methods - they don't return the first/last elements, they just remove them. RemoveFirst
和RemoveLast
都是void
方法-它们不返回前一个/后一个元素,而只是将其删除。
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. 您需要使用First
和Last
属性,然后再删除第一个和最后一个值-假设您确实要删除该值。 (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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.