Roses/Assets/Scripts/Extensions/LimitedSizeList.cs
2024-04-14 23:15:50 +02:00

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);
}
}
}
}