ソースコード
using System.Collections.Generic;
public static class ListExtensions
{
<summary>
</summary>
public static T Dequeue<T>( this IList<T> self )
{
var result = self[ 0 ];
self.RemoveAt( 0 );
return result;
}
<summary>
</summary>
public static void Enqueue<T>( this IList<T> self, T item )
{
self.Add( item );
}
<summary>
</summary>
public static T Peek<T>( this IList<T> self )
{
return self[ 0 ];
}
}
使用例
var list = new List<int>{ 1, 2, 3, 4, 5 };
list.Dequeue();
list.Enqueue( 6 );
list.Peek();
var list = new List<string>
{
"ピカチュウ",
"カイリュー",
"ヤドラン",
};
Debug.Log( list.Dequeue() );
Debug.Log( list.Dequeue() );
Debug.Log( list.Dequeue() );
関連記事