예제 #1
0
파일: List.cs 프로젝트: wecing/coreclr
        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);
        }
예제 #2
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);
        }
예제 #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
 public int IndexOf(T item, int index, int count)
 {
     if (index > this._size)
     {
         ThrowHelper.ThrowArgumentOutOfRange_IndexException();
     }
     if (count < 0 || index > this._size - count)
     {
         ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count();
     }
     return(Array.IndexOf <T>(this._items, item, index, count));
 }
예제 #5
0
파일: List.cs 프로젝트: wecing/coreclr
        // Returns the index of the first occurrence of a given value in a range of
        // this list. The list is searched forwards, starting at index
        // index and upto count number of elements. The
        // elements of the list are compared to the given value using the
        // Object.Equals method.
        //
        // This method uses the Array.IndexOf method to perform the
        // search.
        //
        public int IndexOf(T item, int index, int count)
        {
            if (index > _size)
            {
                ThrowHelper.ThrowArgumentOutOfRange_IndexException();
            }

            if (count < 0 || index > _size - count)
            {
                ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count();
            }
            Contract.Ensures(Contract.Result <int>() >= -1);
            Contract.Ensures(Contract.Result <int>() < Count);
            Contract.EndContractBlock();

            return(Array.IndexOf(_items, item, index, count));
        }
예제 #6
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);
        }