C# Array FindIndex() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Array

Definition

In C#, Array.FindIndex returns the index of the first element that passes your predicate. If nothing matches, it returns -1.

Prefer FindIndex when you need to update that slot or slice around it. Prefer Find when you only need the element value.

This is a static member of System.Array. You call it with the class name, such as Array.FindIndex(...). Arrays in C# have a fixed length after creation; use List<T> when the count must grow.

Syntax

Pass the array and predicate. Check for -1 before indexing.

C#
int ix = Array.FindIndex(nums, x => x > 20);
CallWhat it does
Array.FindIndex(nums, x => x > 20)Index of first int > 20, or -1.
Array.FindIndex(nums, 1, x => x > 20)Start scanning at index 1.

FindLastIndex searches from the end. IndexOf is for equality only.

Library declarations
C#
public static int FindIndex<T>(T[] array, Predicate<T> match);

Parameters

ParameterDescription
arrayRequired. Array to search.
matchRequired. Predicate returning true for a match.
startIndexOptional overload. Where to begin.

Return Value

Return ValueDescription
indexFirst matching position.
-1No match.

C# Examples

Example 1 — Index of First Match

Find where the first value greater than 20 sits.

C#
using System;

class Program {
    static void Main() {
        int[] nums = { 5, 12, 25, 8 };
        int ix = Array.FindIndex(nums, x => x > 20);

        Console.WriteLine("index = " + ix);
        Console.WriteLine("value = " + nums[ix]);
    }
}

How It Works

  1. Predicate scan. Indexes 0 and 1 fail the test.
  2. Index 2 hits. 25 is greater than 20.
  3. Use the index. Reading nums[ix] shows the element.
  4. Safe here. We know a match exists; still check -1 in real code.

Example 2 — Return -1 When Absent

A predicate that never matches yields -1.

C#
using System;

class Program {
    static void Main() {
        string[] names = { "Ann", "Bob" };
        int ix = Array.FindIndex(names, n => n.StartsWith("Z"));
        Console.WriteLine(ix);
    }
}

How It Works

  1. No Z names. Predicate always false.
  2. Sentinel -1. Same pattern as IndexOf.
  3. Do not index. names[-1] would throw.
  4. Vs Find. Find would return null instead of -1.

Example 3 — Start Mid-Array

Skip earlier elements by passing a start index.

C#
using System;

class Program {
    static void Main() {
        int[] nums = { 30, 5, 40, 8 };
        int ix = Array.FindIndex(nums, 1, x => x > 20);

        Console.WriteLine(ix);
    }
}

How It Works

  1. Start at 1. The leading 30 is ignored.
  2. Next candidate. 5 fails; 40 succeeds at index 2.
  3. Windowing. Useful after you already handled an earlier hit.
  4. Count overloads. You can also limit how many elements to scan.

Frequently Asked Questions

It returns -1.
Find returns the element (or default). FindIndex returns the index (or -1).
IndexOf matches by equality. FindIndex matches by any predicate you supply.
Yes. Overloads accept startIndex and optional count.
Use FindLastIndex.

Next: FindLast()

Return the last element that matches a predicate, or default if none with System.Array.

FindLast() 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.

12 people found this page helpful