METHOD
List<T>.BinarySearch
Searches a list already sorted by the same comparer. A negative result encodes the insertion position as its bitwise complement; do not assume which duplicate index is returned.
Formal Syntax & Structure
csharp syntaxcsharp
items.BinarySearch(value)Working Example
Example Snippetcsharp
using System;using System.Collections.Generic;var items = new List<int> { 2, 4, 8 };Console.WriteLine(~items.BinarySearch(5)); // 2