C# List FindLast

Description

List FindLast searches for an element that matches the conditions defined by the specified predicate, and returns the last occurrence within the entire List .

Syntax

List.FindLast has the following syntax.


public T FindLast(
  Predicate<T> match
)

Parameters

  • match - The Predicate delegate that defines the conditions of the element to search for.

Returns

List.FindLast method returns The last element that matches the conditions defined by the specified predicate, if found; otherwise, the default value for type T.

Example


using System;/*from  ww w. ja  v a  2 s  . c  om*/
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)
    {
        Book ndx = Books.FindLast(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