C# List FindLastIndex(Int32, Int32, Predicate)

Description

List FindLastIndex(Int32, 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 List that contains the specified number of elements and ends at the specified index.

Syntax


public int FindLastIndex(
  int startIndex,
  int count,//from w  w  w. j  av a2s. co  m
  Predicate<T> match
)

Parameters

  • startIndex - The zero-based starting index of the backward search.
  • count - The number of elements in the section to search.
  • match - The Predicate delegate that defines the conditions of the element to search for.

Returns

List.FindLastIndex(Int32, 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;/* w w w. j a va2  s.  c o m*/
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;

class Program
{
    private static List<Book> Books = new List<Book>();
    public static void Main(string[] args)
    {
        int ndx = Books.FindLastIndex(1,2,FindComputer);
    }
    private static bool FindComputer(Book bk)
    {

        if (bk.Genre == "Computer")
        {
            return true;
        }else{
            return false;
        }

    }
}

public class Book
{
    public string Genre { get; set; }
}




















Home »
  C# Tutorial »
    System.Collections.Generic »




HashSet
LinkedList
LinkedListNode
List
Queue
SortedSet
Stack