C# List Find and Exists Examples – Programming, Pseudocode Example, C# Programming Example
C# Linq

C# List Find and Exists Examples

Example 1: (Exists) Returns true if the list contains items matching the specified predicate.

Output:

Example 2: (Exists) Returns false if the list doesn’t contain items matching the specified predicate.

Output:

 

Example 3: (Find) Here we consider the Find() method on List. Find accepts a Predicate, which we can specify as a lambda expression. It returns the first match.

Output:

Example 4: (FindLast) To search backwards, use the FindLast method. FindLast will scan the List from the last element to the first. Here we use FindLast instead of Find.

Output:

 

Example 5: (FindIndex) FindIndex returns the index of the first matching element, starting its search from the first element.

 

Leave a Comment

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