コード例 #1
0
 /// <summary>
 /// Searches the entire sorted <see cref="IBaseListCollection{T}"/> for an element using the specified comparer and returns the zero-based index of the element.
 /// </summary>
 /// <typeparam name="T">The type of elements in the collection.</typeparam>
 /// <param name="collection">The collection to search.</param>
 /// <param name="item">The object to locate. The value can be <b>null</b> for reference types.</param>
 /// <param name="comparer">The <see cref="IComparer{T}"/> implementation to use when comparing elements.</param>
 /// <returns>The zero-based index of item in the sorted <see cref="IBaseListCollection{T}"/>, if <paramref name="item"/> is found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger than <paramref name="item"/> or, if there is no larger element, the bitwise complement of <see cref="Count"/>.</returns>
 public static int BinarySearch <T>(this IBaseListCollection <T> collection, T item, IComparer <T> comparer)
 {
     return(collection.BinarySearch(0, collection.Count, item, comparer));
 }
コード例 #2
0
 /// <summary>
 /// Searches the entire sorted <see cref="IBaseListCollection{T}"/> for an element using the default comparer and returns the zero-based index of the element.
 /// </summary>
 /// <typeparam name="T">The type of elements in the collection.</typeparam>
 /// <param name="collection">The collection to search.</param>
 /// <param name="item">The object to locate. The value can be <b>null</b> for reference types.</param>
 /// <returns>The zero-based index of item in the sorted <see cref="IBaseListCollection{T}"/>, if <paramref name="item"/> is found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger than <paramref name="item"/> or, if there is no larger element, the bitwise complement of <see cref="Count"/>.</returns>
 public static int BinarySearch <T>(this IBaseListCollection <T> collection, T item)
 {
     return(collection.BinarySearch(0, collection.Count, item, null));
 }