Skip to content

Instantly share code, notes, and snippets.

@erinxocon
Last active September 11, 2016 21:37
Show Gist options
  • Save erinxocon/1f975d74064c1afdb2d8cf39521fc729 to your computer and use it in GitHub Desktop.
Save erinxocon/1f975d74064c1afdb2d8cf39521fc729 to your computer and use it in GitHub Desktop.
public class FixedSizedLinkedList<T> : LinkedList<T>
{
private readonly object syncObject = new object();
public int Size { get; private set; }
public FixedSizedLinkedList(int size)
{
Size = size;
}
public new void AddFirst(T obj)
{
base.AddFirst(obj);
lock (syncObject)
{
while (base.Count > Size)
{
base.RemoveLast();
}
}
}
public new void AddLast (T obj)
{
base.AddLast(obj);
lock (syncObject)
{
while (base.Count > Size)
{
base.RemoveFirst();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment