diff --git a/Recyclable.Collections/RecyclableArrayList.cs b/Recyclable.Collections/RecyclableArrayList.cs index 348cfb1..1d4bce4 100644 --- a/Recyclable.Collections/RecyclableArrayList.cs +++ b/Recyclable.Collections/RecyclableArrayList.cs @@ -6,6 +6,7 @@ namespace Recyclable.Collections { public class RecyclableArrayList : IEnumerable, IList, IDisposable { + private const int ItemNotFound = -1; private static readonly ArrayPool _arrayPool = ArrayPool.Create(); private static readonly IEqualityComparer _equalityComparer = EqualityComparer.Default; @@ -388,7 +389,7 @@ namespace Recyclable.Collections } } - public int IndexOf(T itemToFind) => Array.IndexOf(_memoryBlock, itemToFind, 0, _count); + public int IndexOf(T itemToFind) => _count > 0 ? Array.IndexOf(_memoryBlock, itemToFind, 0, _count) : ItemNotFound; public void Insert(int index, T item) {