List of videos in .net
3 answers
Here's a simple implementation for that:
public class LimitList<T> : IEnumerable<T>
{
private LinkedList<T> _list = new LinkedList<T>();
public LimitList(int maximumCount)
{
if (maximumCount <= 0)
throw new ArgumentException(null, "maximumCount");
MaximumCount = maximumCount;
}
public int MaximumCount { get; private set; }
public int Count
{
get
{
return _list.Count;
}
}
public void Add(T value)
{
if (_list.Count == MaximumCount)
{
_list.RemoveFirst();
}
_list.AddLast(value);
}
public T this[int index]
{
get
{
if (index < 0 || index >= Count)
throw new ArgumentOutOfRangeException();
return _list.Skip(index).First();
}
}
public IEnumerator<T> GetEnumerator()
{
return _list.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
+2
source to share
Microsoft's standard class doesn't exist for you. But you can take a look at the Queue <> class.
One problem is that Queue <> class auto expand. Can you solve this issue in this thread Limit <T> Queue Size in .NET?
Access to any element capable of the extended method. For example:
LogItem result = collection.Where(x => x.ID == 100).FirstOrDefault();
0
source to share