Array.Find ジェネリック メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > Array.Find ジェネリック メソッドの意味・解説 

Array.Find ジェネリック メソッド

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

指定され述語によって定義され条件一致する要素検索しArray 全体の中で最もインデックス番号小さ要素返します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

例外例外
例外種類条件

ArgumentNullException

arraynull 参照 (Visual Basic では Nothing) です。

または

matchnull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

Predicate デリゲートFind ジェネリック メソッド使用してPoint 構造体配列検索するコード例次に示します。X フィールドと Y フィールドの積が 100,000超える場合は、デリゲートが表す ProductGT10 メソッドから true返りますFind メソッドでは、配列各要素に対してデリゲート呼び出されテスト条件を満たす最初ポイント返されます。

メモメモ

Visual BasicC#ユーザーは、デリゲート明示的に作成する要はありません。また、ジェネリック メソッド型引数指定する必要もありません。コンパイラでは、指定するメソッド引数から必要な型を判断します

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
 */
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Array クラス
Array メンバ
System 名前空間
Exists
FindLast
FindAll
FindIndex
FindLastIndex
BinarySearch
IndexOf
LastIndexOf
Predicate


このページでは「.NET Framework クラス ライブラリ リファレンス」からArray.Find ジェネリック メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からArray.Find ジェネリック メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からArray.Find ジェネリック メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「Array.Find ジェネリック メソッド」の関連用語

Array.Find ジェネリック メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Array.Find ジェネリック メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS