C# Array Find() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Array

Definition

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"));
CallWhat 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

ParameterDescription
arrayRequired. Array to search.
matchRequired. Predicate that returns true for a match.

Return Value

Return ValueDescription
TFirst 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);
    }
}

How It Works

  1. Predicate. x => x > 20 is the yes/no test.
  2. Left to right. 5 and 12 fail; 25 succeeds.
  3. Stop early. Find does not keep looking after the first hit.
  4. 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);
    }
}

How It Works

  1. No Z names. The predicate never returns true.
  2. Default for string. Find returns null.
  3. Null check. Print a placeholder instead of crashing.
  4. 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);
    }
}

How It Works

  1. Method group. IsEven matches Predicate<int>.
  2. Readable tests. Named methods help when the rule is longer.
  3. First even. 8 is the first even value.
  4. 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.
Use Array.FindAll.
Use Array.FindIndex.

Next: FindAll()

Return a new array of every element that matches a predicate with System.Array.

FindAll() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P πŸ”—

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful