21 lines
No EOL
395 B
C#
21 lines
No EOL
395 B
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Extensions {
|
|
public class LimitedSizeList<T> {
|
|
public readonly List<T> List;
|
|
private readonly int _maxSize;
|
|
|
|
public LimitedSizeList(int maxSize) {
|
|
_maxSize = maxSize;
|
|
List = new List<T>(maxSize);
|
|
}
|
|
|
|
public void Add(T item) {
|
|
List.Add(item);
|
|
if (List.Count > _maxSize) {
|
|
List.RemoveAt(0);
|
|
}
|
|
}
|
|
}
|
|
} |