本文整理匯總了C#中System.Array.FindLastIndex方法的典型用法代碼示例。如果您正苦於以下問題:C# Array.FindLastIndex方法的具體用法?C# Array.FindLastIndex怎麽用?C# Array.FindLastIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Array
的用法示例。
在下文中一共展示了Array.FindLastIndex方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
using System;
public class Example
{
public static void Main()
{
string[] dinosaurs = { "Compsognathus",
"Amargasaurus", "Oviraptor", "Velociraptor",
"Deinonychus", "Dilophosaurus", "Gallimimus",
"Triceratops" };
Console.WriteLine();
foreach(string dinosaur in dinosaurs)
{
Console.WriteLine(dinosaur);
}
Console.WriteLine(
"\nArray.FindLastIndex(dinosaurs, EndsWithSaurus): {0}",
Array.FindLastIndex(dinosaurs, EndsWithSaurus));
Console.WriteLine(
"\nArray.FindLastIndex(dinosaurs, 4, EndsWithSaurus): {0}",
Array.FindLastIndex(dinosaurs, 4, EndsWithSaurus));
Console.WriteLine(
"\nArray.FindLastIndex(dinosaurs, 4, 3, EndsWithSaurus): {0}",
Array.FindLastIndex(dinosaurs, 4, 3, EndsWithSaurus));
}
// Search predicate returns true if a string ends in "saurus".
private static bool EndsWithSaurus(String s)
{
if ((s.Length > 5) &&
(s.Substring(s.Length - 6).ToLower() == "saurus"))
{
return true;
}
else
{
return false;
}
}
}
輸出:
Compsognathus Amargasaurus Oviraptor Velociraptor Deinonychus Dilophosaurus Gallimimus Triceratops Array.FindLastIndex(dinosaurs, EndsWithSaurus): 5 Array.FindLastIndex(dinosaurs, 4, EndsWithSaurus): 1 Array.FindLastIndex(dinosaurs, 4, 3, EndsWithSaurus): -1