33 lines
No EOL
616 B
C#
33 lines
No EOL
616 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
public override string ToString() {
|
|
StringBuilder result = new();
|
|
|
|
foreach (T element in List) {
|
|
result.AppendLine(element.ToString());
|
|
}
|
|
|
|
return result.ToString();
|
|
}
|
|
}
|
|
} |