C# Array FindLastIndex() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Array

Definition

In C#, Array.FindLastIndex returns the index of the last element that satisfies your predicate. Missing matches return -1.

It pairs with FindIndex the same way LastIndexOf pairs with IndexOf, but uses a custom condition instead of equality.

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

Syntax

Pass the array and predicate; guard against -1.

C#
int ix = Array.FindLastIndex(nums, x => x > 10);
CallWhat it does
Array.FindLastIndex(nums, x => x > 10)Last index where value > 10, or -1.

Overloads can start from a given index and limit the count.

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

Parameters

ParameterDescription
arrayRequired. Array to search.
matchRequired. Predicate for a match.

Return Value

Return ValueDescription
indexLast matching position.
-1No match.

C# Examples

Example 1 — Last Matching Index

Locate the last int greater than 10.

C#
using System;

class Program {
    static void Main() {
        int[] nums = { 4, 25, 8, 30, 2 };
        int ix = Array.FindLastIndex(nums, x => x > 10);
        Console.WriteLine(ix);
        Console.WriteLine(nums[ix]);
    }
}

How It Works

  1. Index 3. That slot holds 30.
  2. Earlier 25. Index 1 also matches but is not last.
  3. Read value. nums[ix] confirms the element.
  4. Clear miss signal. -1 would mean none matched.

Example 2 — -1 When Absent

No element passes the test.

C#
using System;

class Program {
    static void Main() {
        int[] nums = { 1, 2, 3 };
        int ix = Array.FindLastIndex(nums, x => x > 100);
        Console.WriteLine(ix);
    }
}

How It Works

  1. All fail. Nothing exceeds 100.
  2. Sentinel. Result is -1.
  3. Branch on miss. Skip updates when ix < 0.
  4. Same as FindIndex. Only direction differs.

Example 3 — First Index vs Last Index

Print both ends for even numbers.

C#
using System;

class Program {
    static void Main() {
        int[] nums = { 2, 3, 4, 5, 6 };
        Console.WriteLine("first even @ " + Array.FindIndex(nums, x => x % 2 == 0));
        Console.WriteLine("last even @ " + Array.FindLastIndex(nums, x => x % 2 == 0));
    }
}

How It Works

  1. First even. Index 0 holds 2.
  2. Last even. Index 4 holds 6.
  3. Same predicate. Only the search direction changes.
  4. Handy pair. Use both to know the span of matches.

Frequently Asked Questions

It returns -1.
FindLast returns the element (or default). FindLastIndex returns the index (or -1).
LastIndexOf uses equality. FindLastIndex uses a predicate.
Yes. Overloads accept startIndex and count.
No.

Next: ForEach()

Run an action once for every element in a T[] array with System.Array.

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

14 people found this page helpful