Array.Find ジェネリック メソッド
アセンブリ: mscorlib (mscorlib.dll 内)

Dim array As T() Dim match As Predicate(Of T) Dim returnValue As T returnValue = Array.Find(array, match)
パラメータ
戻り値
見つかった場合は、指定された述語によって定義された条件と一致する最初の要素。それ以外の場合は、型 T の既定値。


Predicate は、渡されたオブジェクトがデリゲートで定義された条件と一致した場合にtrue を返すメソッドのデリゲートです。array の要素は、それぞれ Predicate に渡されます。この処理は、Array 内の先頭の要素から、最後の要素まで繰り返し行われます。一致する要素が見つかった時点で処理が終了します。

Predicate デリゲートと Find ジェネリック メソッドを使用して、Point 構造体の配列を検索するコード例を次に示します。X フィールドと Y フィールドの積が 100,000 を超える場合は、デリゲートが表す ProductGT10 メソッドから true が返ります。Find メソッドでは、配列の各要素に対してデリゲートが呼び出され、テスト条件を満たす最初のポイントが返されます。
![]() |
---|
Visual Basic や C# のユーザーは、デリゲートを明示的に作成する必要はありません。また、ジェネリック メソッドの型引数を指定する必要もありません。コンパイラでは、指定するメソッドの引数から必要な型を判断します。 |
Imports System Imports System.Drawing Public Class Example Public Shared Sub Main() ' Create an array of five Point structures. Dim points() As Point = { new Point(100, 200), _ new Point(150, 250), new Point(250, 375), _ new Point(275, 395), new Point(295, 450) } ' To find the first Point structure for which X times Y ' is greater than 100000, pass the array and a delegate ' that represents the ProductGT10 method to the Shared ' Find method of the Array class. Dim first As Point = Array.Find(points, _ AddressOf ProductGT10) ' Note that you do not need to create the delegate ' explicitly, or to specify the type parameter of the ' generic method, because the compiler has enough ' context to determine that information for you. ' Display the first structure found. Console.WriteLine("Found: X = {0}, Y = {1}", _ first.X, first.Y) End Sub ' This method implements the test condition for the Find ' method. Private Shared Function ProductGT10(ByVal p As Point) As Boolean If p.X * p.Y > 100000 Then Return True Else Return False End If End Function End Class ' This code example produces the following output: ' 'Found: X = 275, Y = 395
using System; using System.Drawing; public class Example { public static void Main() { // Create an array of five Point structures. Point[] points = { new Point(100, 200), new Point(150, 250), new Point(250, 375), new Point(275, 395), new Point(295, 450) }; // To find the first Point structure for which X times Y // is greater than 100000, pass the array and a delegate // that represents the ProductGT10 method to the Shared // Find method of the Array class. Point first = Array.Find(points, ProductGT10); // Note that you do not need to create the delegate // explicitly, or to specify the type parameter of the // generic method, because the C# compiler has enough // context to determine that information for you. // Display the first structure found. Console.WriteLine("Found: X = {0}, Y = {1}", first.X, first.Y); } // This method implements the test condition for the Find // method. private static bool ProductGT10(Point p) { if (p.X * p.Y > 100000) { return true; } else { return false; } } } /* This code example produces the following output: Found: X = 275, Y = 395 */

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からArray.Find ジェネリック メソッドを検索する場合は、下記のリンクをクリックしてください。

- Array.Find ジェネリック メソッドのページへのリンク