Is there any way to limit the size of a generic collection?
I have a Stack of WriteableBitmap which I am using to store a clone of a WriteableBitmap on each change,
To elaborate on Tilak's answer here is some example code:
public class LimitedSizeStack : LinkedList
{
private readonly int _maxSize;
public LimitedSizeStack(int maxSize)
{
_maxSize = maxSize;
}
public void Push(T item)
{
this.AddFirst(item);
if(this.Count > _maxSize)
this.RemoveLast();
}
public T Pop()
{
var item = this.First.Value;
this.RemoveFirst();
return item;
}
}