⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 listbase.cs

📁 C#写的类似于STL的集合类,首先是C#编写,可以用于.net变程.
💻 CS
📖 第 1 页 / 共 3 页
字号:
        }

        /// <summary>
        /// Finds the first item in the list that satisfies the condition
        /// defined by <paramref name="predicate"/>. 
        /// </summary>
        /// <param name="predicate">A delegate that defines the condition to check for.</param>
        /// <param name="foundItem">If true is returned, this parameter receives the first item in the list
        /// that satifies the condition defined by <paramref name="predicate"/>.</param>
        /// <returns>True if an item that  satisfies the condition <paramref name="predicate"/> was found. False 
        /// if no item in the list satisfies that condition.</returns>
        public virtual bool TryFind(Predicate<T> predicate, out T foundItem)
        {
            return Algorithms.TryFindFirstWhere<T>(this, predicate, out foundItem);
        }

        /// <summary>
        /// Finds the last item in the list that satisfies the condition
        /// defined by <paramref name="predicate"/>. If no item matches the condition, than
        /// the default value for T (null or all-zero) is returned.
        /// </summary>
        /// <remarks>If the default value for T (null or all-zero) matches the condition defined by <paramref name="predicate"/>,
        /// and the list might contain the default value, then it is impossible to distinguish the different between finding
        /// the default value and not finding any item. To distinguish these cases, use <see cref="TryFindLast"/>.</remarks>
        /// <param name="predicate">A delegate that defined the condition to check for.</param>
        /// <returns>The last item that satisfies the condition <paramref name="predicate"/>. If no item satisfies that
        /// condition, the default value for T is returned.</returns>
        /// <seealso cref="TryFindLast"/>
        public virtual T FindLast(Predicate<T> predicate)
        {
            return Algorithms.FindLastWhere(this, predicate);
        }

        /// <summary>
        /// Finds the last item in the list that satisfies the condition
        /// defined by <paramref name="predicate"/>. 
        /// </summary>
        /// <param name="predicate">A delegate that defines the condition to check for.</param>
        /// <param name="foundItem">If true is returned, this parameter receives the last item in the list
        /// that satifies the condition defined by <paramref name="predicate"/>.</param>
        /// <returns>True if an item that  satisfies the condition <paramref name="predicate"/> was found. False 
        /// if no item in the list satisfies that condition.</returns>
        public virtual bool TryFindLast(Predicate<T> predicate, out T foundItem)
        {
            return Algorithms.TryFindLastWhere<T>(this, predicate, out foundItem);
        }

        /// <summary>
        /// Finds the index of the first item in the list that satisfies the condition
        /// defined by <paramref name="predicate"/>. If no item matches the condition, -1 is returned.
        /// </summary>
        /// <param name="predicate">A delegate that defined the condition to check for.</param>
        /// <returns>The index of the first item that satisfies the condition <paramref name="predicate"/>. If no item satisfies that
        /// condition, -1 is returned.</returns>
        public virtual int FindIndex(Predicate<T> predicate)
        {
            return Algorithms.FindFirstIndexWhere<T>(this, predicate);
        }

        /// <summary>
        /// Finds the index of the first item, in the range of items extending from <paramref name="index"/> to the end, that satisfies the condition
        /// defined by <paramref name="predicate"/>. If no item matches the condition, -1 is returned.
        /// </summary>
        /// <param name="predicate">A delegate that defined the condition to check for.</param>
        /// <param name="index">The starting index of the range to check.</param>
        /// <returns>The index of the first item in the given range that satisfies the condition <paramref name="predicate"/>. If no item satisfies that
        /// condition, -1 is returned.</returns>
        public virtual int FindIndex(int index, Predicate<T> predicate)
        {
            int foundIndex = Algorithms.FindFirstIndexWhere<T>(Range(index, Count - index), predicate);
            if (foundIndex < 0)
                return -1;
            else
                return foundIndex + index;
        }

        /// <summary>
        /// Finds the index of the first item, in the range of <paramref name="count"/> items starting from <paramref name="index"/>, that satisfies the condition
        /// defined by <paramref name="predicate"/>. If no item matches the condition, -1 is returned.
        /// </summary>
        /// <param name="predicate">A delegate that defined the condition to check for.</param>
        /// <param name="index">The starting index of the range to check.</param>
        /// <param name="count">The number of items in range to check.</param>
        /// <returns>The index of the first item in the given range that satisfies the condition <paramref name="predicate"/>. If no item satisfies that
        /// condition, -1 is returned.</returns>
        public virtual int FindIndex(int index, int count, Predicate<T> predicate)
        {
            int foundIndex = Algorithms.FindFirstIndexWhere<T>(Range(index, count), predicate);
            if (foundIndex < 0)
                return -1;
            else
                return foundIndex + index;
        }

        /// <summary>
        /// Finds the index of the last item in the list that satisfies the condition
        /// defined by <paramref name="predicate"/>. If no item matches the condition, -1 is returned.
        /// </summary>
        /// <param name="predicate">A delegate that defined the condition to check for.</param>
        /// <returns>The index of the last item that satisfies the condition <paramref name="predicate"/>. If no item satisfies that
        /// condition, -1 is returned.</returns>
        public virtual int FindLastIndex(Predicate<T> predicate)
        {
            return Algorithms.FindLastIndexWhere<T>(this, predicate);
        }

        /// <summary>
        /// Finds the index of the last item, in the range of items extending from the beginning
        /// of the list to <paramref name="index"/>, that satisfies the condition
        /// defined by <paramref name="predicate"/>. If no item matches the condition, -1 is returned.
        /// </summary>
        /// <param name="predicate">A delegate that defined the condition to check for.</param>
        /// <param name="index">The ending index of the range to check.</param>
        /// <returns>The index of the last item in the given range that satisfies the condition <paramref name="predicate"/>. If no item satisfies that
        /// condition, -1 is returned.</returns>
        public virtual int FindLastIndex(int index, Predicate<T> predicate)
        {
            return Algorithms.FindLastIndexWhere<T>(Range(0, index + 1), predicate);
        }

        /// <summary>
        /// Finds the index of the last item, in the range of <paramref name="count"/> items ending at <paramref name="index"/>, that satisfies the condition
        /// defined by <paramref name="predicate"/>. If no item matches the condition, -1 is returned.
        /// </summary>
        /// <param name="predicate">A delegate that defined the condition to check for.</param>
        /// <param name="index">The ending index of the range to check.</param>
        /// <param name="count">The number of items in range to check.</param>
        /// <returns>The index of the last item in the given range that satisfies the condition <paramref name="predicate"/>. If no item satisfies that
        /// condition, -1 is returned.</returns>
        public virtual int FindLastIndex(int index, int count, Predicate<T> predicate)
        {
            int foundIndex = Algorithms.FindLastIndexWhere<T>(Range(index - count + 1, count), predicate);

            if (foundIndex >= 0)
                return foundIndex + index - count + 1;
            else
                return -1;
        }

        /// <summary>
        /// Finds the index of the first item in the list that is equal to <paramref name="item"/>. 
        /// </summary>
        /// <remarks>The default implementation of equality for type T is used in the search. This is the
        /// equality defined by IComparable&lt;T&gt; or object.Equals.</remarks>
        /// <param name="item">The item to search fror.</param>
        /// <returns>The index of the first item in the list that that is equal to <paramref name="item"/>.  If no item is equal
        /// to <paramref name="item"/>, -1 is returned.</returns>
        public virtual int IndexOf(T item)
        {
            return Algorithms.FirstIndexOf<T>(this, item, EqualityComparer<T>.Default);
        }

        /// <summary>
        /// Finds the index of the first item, in the range of items extending from <paramref name="index"/> to the end,  
        /// that is equal to <paramref name="item"/>. 
        /// </summary>
        /// <remarks>The default implementation of equality for type T is used in the search. This is the
        /// equality defined by IComparable&lt;T&gt; or object.Equals.</remarks>
        /// <param name="item">The item to search fror.</param>
        /// <param name="index">The starting index of the range to check.</param>
        /// <returns>The index of the first item in the given range that that is equal to <paramref name="item"/>.  If no item is equal
        /// to <paramref name="item"/>, -1 is returned.</returns>
        public virtual int IndexOf(T item, int index)
        {
            int foundIndex = Algorithms.FirstIndexOf<T>(Range(index, Count - index), item, EqualityComparer<T>.Default);

            if (foundIndex >= 0)
                return foundIndex + index;
            else
                return -1;
        }

        /// <summary>
        /// Finds the index of the first item, in the range of <paramref name="count"/> items starting from <paramref name="index"/>,  
        /// that is equal to <paramref name="item"/>. 
        /// </summary>
        /// <remarks>The default implementation of equality for type T is used in the search. This is the
        /// equality defined by IComparable&lt;T&gt; or object.Equals.</remarks>
        /// <param name="item">The item to search fror.</param>
        /// <param name="index">The starting index of the range to check.</param>
        /// <param name="count">The number of items in range to check.</param>
        /// <returns>The index of the first item in the given range that that is equal to <paramref name="item"/>.  If no item is equal
        /// to <paramref name="item"/>, -1 is returned.</returns>
        public virtual int IndexOf(T item, int index, int count)
        {
            int foundIndex = Algorithms.FirstIndexOf<T>(Range(index, count), item, EqualityComparer<T>.Default);

            if (foundIndex >= 0)
                return foundIndex + index;
            else
                return -1;
        }

        /// <summary>
        /// Finds the index of the last item in the list that is equal to <paramref name="item"/>. 
        /// </summary>
        /// <remarks>The default implementation of equality for type T is used in the search. This is the
        /// equality defined by IComparable&lt;T&gt; or object.Equals.</remarks>
        /// <param name="item">The item to search fror.</param>
        /// <returns>The index of the last item in the list that that is equal to <paramref name="item"/>.  If no item is equal
        /// to <paramref name="item"/>, -1 is returned.</returns>
        public virtual int LastIndexOf(T item)
        {
            return Algorithms.LastIndexOf<T>(this, item, EqualityComparer<T>.Default);
        }

        /// <summary>
        /// Finds the index of the last item, in the range of items extending from the beginning
        /// of the list to <paramref name="index"/>, that is equal to <paramref name="item"/>. 
        /// </summary>
        /// <remarks>The default implementation of equality for type T is used in the search. This is the
        /// equality defined by IComparable&lt;T&gt; or object.Equals.</remarks>
        /// <param name="item">The item to search fror.</param>
        /// <param name="index">The ending index of the range to check.</param>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -