C# List

How to Search a C# List Elements?

In this tutorial, i’ll show you How to search C# List elements.

The BinarySearch method of List<T> searches a sorted list and returns the zero-based index of the found item. The List<T> must be sorted before this method can be used. 

The following code snippet returns an index of a string in a List.

Example:

Output:

0
3
-2

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.