C# List FindIndex(Int32, Int32, Predicate)
Description
List
searches
for an element that matches the conditions defined by the specified predicate,
and returns the zero-based index of the first occurrence within the range
of elements in the List
Syntax
public int FindIndex(
int startIndex,
int count,/*from w w w . j a v a 2 s . c o m*/
Predicate<T> match
)
Parameters
startIndex
- The zero-based starting index of the search.count
- The number of elements in the section to search.match
- The Predicatedelegate that defines the conditions of the element to search for.
Returns
List.FindIndex(Int32, Int32, Predicate)
method returns The zero-based
index of the first occurrence of an element that matches the
conditions defined by match, if found; otherwise, -1.
Example
using System;//from w w 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)
{
int ndx = Books.FindIndex(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; }
}