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);
Call
What 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
Parameter
Description
array
Required. Array to search.
match
Required. Predicate for a match.
Return Value
Return Value
Description
index
Last matching position.
-1
No 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]);
}
}
Output
3
30
How It Works
Index 3. That slot holds 30.
Earlier 25. Index 1 also matches but is not last.
Read value.nums[ix] confirms the element.
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);
}
}
Output
-1
How It Works
All fail. Nothing exceeds 100.
Sentinel. Result is -1.
Branch on miss. Skip updates when ix < 0.
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));
}
}
Output
first even @ 0
last even @ 4
How It Works
First even. Index 0 holds 2.
Last even. Index 4 holds 6.
Same predicate. Only the search direction changes.
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.