C# Array.Find() Method with Examples – Programming, Pseudocode Example, C# Programming Example
C# C# Console Linq

C# Array.Find() Method with Examples

The Array.Find() method searches for an element that matches the specified conditions using predicate delegate, and returns the first occurrence within the entire Array.

As per the syntax, the first parameter is a one-dimensional array to search and the second parameter is the predicate deligate which can be a lambda expression. It returns the first element that satisfy the conditions defined by the predicate expression; otherwise, returns the default value for type T.

The following example finds the first element that matches with string “Toni”.

C# Code

Output:

Toni

Example 2:

The following example returns the first element that starts with “B”.

Example 3:

The following example returns the first element, whose length is five or more.

Notice that the Array.Find() method only returns the first occurrence and not all matching elements. Use the Array.FindAll() method to retrieve all matching elements.

Leave a Comment

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

%d bloggers like this: