Predicate ジェネリック デリゲートとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > Predicate ジェネリック デリゲートの意味・解説 

Predicate ジェネリック デリゲート

メモ : このデリゲートは、.NET Framework version 2.0新しく追加されたものです。

一連の基準定義し指定されオブジェクトがこれらの基準満たしているかどうか判断するメソッド表します

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

解説解説
使用例使用例

Predicate デリゲートと Array.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
 */
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


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

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

辞書ショートカット

すべての辞書の索引

「Predicate ジェネリック デリゲート」の関連用語

Predicate ジェネリック デリゲートのお隣キーワード
検索ランキング

   

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



Predicate ジェネリック デリゲートのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS