In C#, Array.Find scans an array and returns the first element that matches a condition you provide. The condition is a predicateβa small function that returns true or false for one element. Beginners often write it as a lambda: x => x > 10.
If nothing matches, Find returns the default value for the element type (0 for int, null for string and other reference types).
This is a static member of System.Array. You call it with the class name, such as Array.Find(...). Arrays in C# have a fixed length after creation; use List<T> when the count must grow.
Syntax
Pass the array and a predicate. Read the result carefully when it might be default.
C#
int hit = Array.Find(nums, x => x > 20);
string name = Array.Find(names, n => n.StartsWith("C"));
Call
What it does
Array.Find(nums, x => x > 20)
First int greater than 20, or 0 if none.
Array.Find(names, n => n.Length > 3)
First long name, or null if none.
Need every match? Use FindAll. Need the index? Use FindIndex. Need a yes/no only? Use Exists.
Library declarations
C#
public static T Find<T>(T[] array, Predicate<T> match);
Parameters
Parameter
Description
array
Required. Array to search.
match
Required. Predicate that returns true for a match.
Return Value
Return Value
Description
T
First matching element, or default(T) when no element matches.
C# Examples
Example 1 — First Number Above a Limit
Find the first int greater than 20.
C#
using System;
class Program {
static void Main() {
int[] nums = { 5, 12, 25, 8 };
int hit = Array.Find(nums, x => x > 20);
Console.WriteLine(hit);
}
}
Output
25
How It Works
Predicate.x => x > 20 is the yes/no test.
Left to right. 5 and 12 fail; 25 succeeds.
Stop early. Find does not keep looking after the first hit.
Returns the element. You get 25 itself, not its index.
Example 2 — Null When No String Matches
Search names and handle a missing match.
C#
using System;
class Program {
static void Main() {
string[] names = { "Ann", "Bob" };
string hit = Array.Find(names, n => n.StartsWith("Z"));
Console.WriteLine(hit == null ? "(none)" : hit);
}
}
Output
(none)
How It Works
No Z names. The predicate never returns true.
Default for string. Find returns null.
Null check. Print a placeholder instead of crashing.
Alternative. FindIndex would return -1 for the same miss.
Example 3 — Use a Named Predicate Method
Pass a method group instead of an inline lambda.
C#
using System;
class Program {
static bool IsEven(int n) {
return n % 2 == 0;
}
static void Main() {
int[] nums = { 3, 7, 8, 9 };
int hit = Array.Find(nums, IsEven);
Console.WriteLine(hit);
}
}
Output
8
How It Works
Method group.IsEven matches Predicate<int>.
Readable tests. Named methods help when the rule is longer.
First even. 8 is the first even value.
Same as lambda.x => x % 2 == 0 would behave identically.
Frequently Asked Questions
A function that takes one element and returns true or false. Lambdas like x => x > 10 are common.
default(T): null for reference types, 0 for int, false for bool, and so on.
IndexOf looks for an equal value. Find uses any condition you write in the predicate.