/// <summary> /// Determines whether the <see cref="T:System.Collections.Generic.ICollection`1"/> contains a specific value. /// </summary> /// <returns> /// true if <paramref name="item"/> is found in the <see cref="T:System.Collections.Generic.ICollection`1"/>; otherwise, false. /// </returns> /// <param name="item">The object to locate in the <see cref="T:System.Collections.Generic.ICollection`1"/>. /// </param> public bool Contains(T item) { ValueLock.EnterReadLock(); try { for (int i = 0; i < Count; i++) { if (this[i].Equals(item)) { return(true); } } } finally { ValueLock.ExitReadLock(); } return(false); }
/// <summary> /// Determines the index of a specific item in the <see cref="T:System.Collections.Generic.IList`1"/>. /// </summary> /// <returns> /// The index of <paramref name="item"/> if found in the list; otherwise, -1. /// </returns> /// <param name="item">The object to locate in the <see cref="T:System.Collections.Generic.IList`1"/>. /// </param> public int IndexOf(T item) { ValueLock.EnterReadLock(); try { int index; for (index = 0; index < Count; index++) { if (!this[index].Equals(item)) { continue; } return(index); } return(-1); } finally { ValueLock.ExitReadLock(); } }
public T this[int index] { get { ValueLock.EnterReadLock(); try { if (index >= Count || index < 0) { string msg = string.Format("Tried to access item outside the array boundaries. {0}/{1}", index, Count); throw new ArgumentOutOfRangeException(msg); } return(base[index]); } finally { ValueLock.ExitReadLock(); } } set { if (index < 0) { throw new ArgumentOutOfRangeException("Tried to access item outside the array boundaries"); } try { ValueLock.EnterWriteLock(); if (index >= Count) { throw new ArgumentOutOfRangeException("Tried to access item outside the array boundaries"); } base[index] = value; } finally { ValueLock.ExitWriteLock(); } } }
/// <summary> /// Copies the elements of the <see cref="T:System.Collections.Generic.ICollection`1"/> to an <see cref="T:System.Array"/>, starting at a particular <see cref="T:System.Array"/> index. /// </summary> /// <param name="array">The one-dimensional <see cref="T:System.Array"/> that is the destination of the elements copied from <see cref="T:System.Collections.Generic.ICollection`1"/>. The <see cref="T:System.Array"/> must have zero-based indexing. /// </param><param name="arrayIndex">The zero-based index in <paramref name="array"/> at which copying begins. /// </param><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null. /// </exception><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="arrayIndex"/> is less than 0. /// </exception><exception cref="T:System.ArgumentException"><paramref name="array"/> is multidimensional. /// -or- /// <paramref name="arrayIndex"/> is equal to or greater than the length of <paramref name="array"/>. /// -or- /// The number of elements in the source <see cref="T:System.Collections.Generic.ICollection`1"/> is greater than the available space from <paramref name="arrayIndex"/> to the end of the destination <paramref name="array"/>. /// -or- /// Type cannot be cast automatically to the type of the destination <paramref name="array"/>. /// </exception> public void CopyTo(T[] array, int arrayIndex) { if (array == null) { throw new ArgumentNullException("array", "array is null"); } if (arrayIndex < 0) { throw new ArgumentOutOfRangeException("arrayIndex", "index < 0"); } ValueLock.EnterReadLock(); try { if (Count > (array.Length - arrayIndex)) { throw new ArgumentOutOfRangeException("array", "not enough room to copy"); } CopyElementsToArray(array, arrayIndex); } finally { ValueLock.ExitReadLock(); } }