M Marc Gravell Apr 9, 2008 #3 Not with List<T>; however, it would be fairly trivial to inherit from Collection<T> to enforce this: public class BoundCollection<T> : Collection<T> { private readonly int maxCount; public BoundCollection(int maxCount) { if (maxCount <= 0) throw new ArgumentOutOfRangeException("maxCount"); this.maxCount = maxCount; } protected override void InsertItem(int index, T item) { if (Count >= maxCount) { throw new InvalidOperationException("No room"); } base.InsertItem(index, item); } } Marc
Not with List<T>; however, it would be fairly trivial to inherit from Collection<T> to enforce this: public class BoundCollection<T> : Collection<T> { private readonly int maxCount; public BoundCollection(int maxCount) { if (maxCount <= 0) throw new ArgumentOutOfRangeException("maxCount"); this.maxCount = maxCount; } protected override void InsertItem(int index, T item) { if (Count >= maxCount) { throw new InvalidOperationException("No room"); } base.InsertItem(index, item); } } Marc