C# List FindLastIndex(Predicate)
Description
List
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 entire
List
Syntax
public int FindLastIndex(
Predicate<T> match
)
Parameters
match
- The Predicatedelegate that defines the conditions of the element to search for.
Returns
List.FindLastIndex(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;/* www . j ava 2s . com*/
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(FindComputer);
}
private static bool FindComputer(Book bk)
{
if (bk.Genre == "Computer")
{
return true;
}else{
return false;
}
}
}
public class Book
{
public string Genre { get; set; }
}