.NET Array Dictionary List String Sub ArrayList Cast Class Console Dates DataTable DateTime Enum File For Format If IndexOf Lambda LINQ Nothing Parse Process Property Regex Replace Select Sort Split StringBuilder SubstringBinarySearch List. BinarySearch is an optimized search Function. It requires that the List instance is already sorted. It hones in on the value by dividing the number of elements being searched several times. It provides better performance on sorted Lists.
VB.NET program that uses BinarySearch on List Module Module1 Sub Main() Dim animals As List(Of String) = New List(Of String) animals.Add("zebra") animals.Add("mouse") animals.Add("cat") ' This is required! animals.Sort() Dim zebraPosition As Integer = animals.BinarySearch("zebra") Dim catPosition As Integer = animals.BinarySearch("cat") Console.WriteLine(zebraPosition) Console.WriteLine(catPosition) End Sub End Module Output 2 0Performance. As I have progressed with programming, I have realized that methods like BinarySearch are not that useful. Instead, hashtables such as Dictionary are the best for fast lookups. In my programs, I usually just use Dictionary for all lookups.Dictionary
And: The IndexOf method is always faster when your searched-for element is at the start.BinarySearch
However: On sorted Lists where performance is not critical but merely nice to have, BinarySearch has its place.List