Exemple #1
0
        /// <summary>
        /// Returns the index of the first element in the array where predicate is true, and -1 otherwise.
        /// </summary>
        /// <param name="predicate">find calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, findIndex immediately returns that element index. Otherwise, findIndex returns -1.</param>
        /// <returns></returns>
        public int FindIndex(FindIndexCallback predicate)
        {
            for (int index = 0; index < this.Length; index++)
            {
                if (predicate(this[index], index, this))
                {
                    return(index);
                }
            }

            return(-1);
        }
Exemple #2
0
        /// <summary>
        /// Returns the index of the last element in the array where predicate is true, and -1 otherwise if the predicate is never true.
        /// </summary>
        /// <param name="predicate">find calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, findIndex immediately returns that element index. Otherwise, findIndex returns -1.</param>
        /// <returns></returns>
        public int FindLastIndex(FindIndexCallback predicate)
        {
            int lastResult = -1;

            for (int index = 0; index < this.Length; index++)
            {
                if (predicate(this[index], index, this))
                {
                    lastResult = index;
                }
            }

            return(lastResult);
        }