Exemplo n.º 1
0
        /// <summary>Removes the first occurance of the given value from the list.</summary>
        /// <param name="value">Value to remove.</param>
        /// <param name="reverse">True to start at the end of the list.</param>
        public bool Remove(T value, bool reverse)
        {
            ListEnumerator <T> enumerator;

            if (reverse)
            {
                enumerator = new ReverseEnumerator <T>(this);
            }
            else
            {
                enumerator = new ForwardEnumerator <T>(this);
            }

            while (enumerator.MoveNext())
            {
                Node <T> node = (Node <T>)enumerator.CurrentNode;
                if (object.Equals(node.Value, value))
                {
                    RemoveAt(enumerator.CurrentNode);
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        /// <summary>Determines the index of a specific item in the List.</summary>
        /// <param name="value">The object to locate in the list.</param>
        /// <returns>The zero-based index of the object in the list, or -1 if its not in the list.</returns>
        public int IndexOf(T value)
        {
            IEnumerator enumerator = new ForwardEnumerator <T>(this);
            int         index      = -1;

            while (enumerator.MoveNext())
            {
                index++;
                if (object.Equals(enumerator.Current, value))
                {
                    return(index);
                }
            }

            return(-1);  // Didn't find it
        }