C# Array FindLastIndex(T[], Int32, Predicate)

Description

Array FindLastIndex (T[], Int32, Predicate ) searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the last occurrence within the range of elements in the Array that extends from the first element to the specified index.

Syntax

Array.FindLastIndex(T[], Int32, Predicate) has the following syntax.


public static int FindLastIndex<T>(
  T[] array,/*from ww w.  j  a  va2 s.  c o  m*/
  int startIndex,
  Predicate<T> match
)

Parameters

Array.FindLastIndex(T[], Int32, Predicate) has the following parameters.

  • T - The type of the elements of the array.
  • array - The one-dimensional, zero-based Array to search.
  • startIndex - The zero-based starting index of the backward search.
  • match - The Predicate that defines the conditions of the element to search for.

Returns

Array.FindLastIndex(T[], Int32, Predicate) method returns The zero-based index of the last occurrence of an element that matches the conditions defined by match, if found; otherwise, -1.

Example


using System;/*from   w ww .  ja v  a  2  s  . c om*/

public class MainClass
{
    public static void Main()
    {
        string[] myValues ={
            "1234", "19", "3456",
            "3456", "200","5678",
            "6543", "9876"
        };

        Predicate<string> myPredicate = LenCheck;
        Console.WriteLine(Array.FindLastIndex(myValues,0, myPredicate));


    }
    private static bool LenCheck(String s)
    {
        if (s.Length > 3)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version