我想知道是否有一种内置方法可以使用一个方法/命令删除并返回列表的第一个项目。
我使用了这个,但它不太美观。
Item currentItem = items.First();
items.RemoveAt(0);
所以我可以写一个扩展方法:
public static class ListExtensions
{
public static T RemoveAndReturnFirst<T>(this List<T> list)
{
T currentFirst = list.First();
list.RemoveAt(0);
return currentFirst;
}
}
//Example code
Item currentItem = items.RemoveAndReturnFirst();
这是最好的选择吗?还是有内置方法可用?
该列表来自 nHibernate-Query,因此它应该保持为
List<T>
。
List<T>
中或者作为扩展方法可用?如果是,那么答案是否定的。 - CodeCaster