예제 #1
0
        public int FindLastIndex(int startIndex, int count, Predicate <T> match)
        {
            if (match == null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
            }
            if (this._size == 0)
            {
                if (startIndex != -1)
                {
                    ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index();
                }
            }
            else if ((uint)startIndex >= (uint)this._size)
            {
                ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index();
            }
            if (count < 0 || startIndex - count + 1 < 0)
            {
                ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count();
            }
            int num = startIndex - count;

            for (int index = startIndex; index > num; --index)
            {
                if (match(this._items[index]))
                {
                    return(index);
                }
            }
            return(-1);
        }
예제 #2
0
        public int FindIndex(int startIndex, int count, Predicate <T> match)
        {
            if ((uint)startIndex > (uint)_size)
            {
                ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index();
            }

            if (count < 0 || startIndex > _size - count)
            {
                ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count();
            }

            if (match == null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
            }
            Contract.Ensures(Contract.Result <int>() >= -1);
            Contract.Ensures(Contract.Result <int>() < startIndex + count);
            Contract.EndContractBlock();

            int endIndex = startIndex + count;

            for (int i = startIndex; i < endIndex; i++)
            {
                if (match(_items[i]))
                {
                    return(i);
                }
            }
            return(-1);
        }
예제 #3
0
        public int FindIndex(int startIndex, int count, Predicate <T> match)
        {
            if ((uint)startIndex > (uint)this._size)
            {
                ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index();
            }
            if (count < 0 || startIndex > this._size - count)
            {
                ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count();
            }
            if (match == null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
            }
            int num = startIndex + count;

            for (int index = startIndex; index < num; ++index)
            {
                if (match(this._items[index]))
                {
                    return(index);
                }
            }
            return(-1);
        }
예제 #4
0
파일: List.cs 프로젝트: wecing/coreclr
        public int FindLastIndex(int startIndex, int count, Predicate <T> match)
        {
            if (match == null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
            }
            Contract.Ensures(Contract.Result <int>() >= -1);
            Contract.Ensures(Contract.Result <int>() <= startIndex);
            Contract.EndContractBlock();

            if (_size == 0)
            {
                // Special case for 0 length List
                if (startIndex != -1)
                {
                    ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index();
                }
            }
            else
            {
                // Make sure we're not out of range
                if ((uint)startIndex >= (uint)_size)
                {
                    ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index();
                }
            }

            // 2nd have of this also catches when startIndex == MAXINT, so MAXINT - 0 + 1 == -1, which is < 0.
            if (count < 0 || startIndex - count + 1 < 0)
            {
                ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count();
            }

            int endIndex = startIndex - count;

            for (int i = startIndex; i > endIndex; i--)
            {
                if (match(_items[i]))
                {
                    return(i);
                }
            }
            return(-1);
        }