本文整理匯總了C#中System.Array.FindIndex方法的典型用法代碼示例。如果您正苦於以下問題:C# Array.FindIndex方法的具體用法?C# Array.FindIndex怎麽用?C# Array.FindIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Array
的用法示例。
在下文中一共展示了Array.FindIndex方法的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.FindIndex(dinosaurs, EndsWithSaurus): {0}",
Array.FindIndex(dinosaurs, EndsWithSaurus));
Console.WriteLine(
"\nArray.FindIndex(dinosaurs, 2, EndsWithSaurus): {0}",
Array.FindIndex(dinosaurs, 2, EndsWithSaurus));
Console.WriteLine(
"\nArray.FindIndex(dinosaurs, 2, 3, EndsWithSaurus): {0}",
Array.FindIndex(dinosaurs, 2, 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.FindIndex(dinosaurs, EndsWithSaurus): 1 Array.FindIndex(dinosaurs, 2, EndsWithSaurus): 5 Array.FindIndex(dinosaurs, 2, 3, EndsWithSaurus): -1