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

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

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

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

特定の型のオブジェクト別の型のオブジェクト変換する方法表します

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

Public Delegate Function
 Converter(Of TInput, TOutput) ( _
    input As TInput _
) As TOutput
Dim instance As New Converter(Of
 TInput, TOutput)(AddressOf HandlerMethod)
public delegate TOutput Converter<TInput,TOutput> (
    TInput input
)
generic<typename TInput, typename TOutput>
public delegate TOutput Converter (
    TInput input
)
J# では、ジェネリックな型およびメソッド使用できますが、新規に宣言することはできません。
JScript では、ジェネリックな型およびメソッド使用できません。

型パラメータ

TInput

変換するオブジェクトの型。

TOutput

入力オブジェクトの変換後の型。

パラメータ

input

変換対象オブジェクト

戻り値
変換されTInput を表す TOutput

解説解説
使用例使用例

このセクションには、2 つコード例含まれています。最初コード例では、Converter デリゲートArray クラスConvertAll メソッド使用する方法示し2 番目のコード例では、このデリゲートList ジェネリック クラスConvertAll メソッド使用する方法示します

例 1

PointF 構造体Point 構造体変換する PointFToPoint という名前のメソッド定義するコード例次に示します。この例では、次に PointF 構造体配列作成しConverter<PointF, Point> デリゲート (Visual Basic では Converter(Of PointF, Point)) を作成して PointFToPoint メソッド表し、そのデリゲートConvertAll メソッド渡しますConvertAll メソッドは、入力リスト各要素PointFToPoint メソッド渡し変換され要素Point 構造体新しリスト格納します両方リスト表示されます。

Imports System
Imports System.Drawing
Imports System.Collections.Generic

Public Class Example

    Public Shared Sub Main()

        Dim apf() As PointF = { _
            New PointF(27.8, 32.62), _
            New PointF(99.3, 147.273), _
            New PointF(7.5, 1412.2)  }

        Console.WriteLine()
        For Each p As PointF
 In apf
            Console.WriteLine(p)
        Next

        Dim ap() As Point = Array.ConvertAll(apf,
 _
            New Converter(Of PointF, Point)(AddressOf
 PointFToPoint))

        Console.WriteLine()
        For Each p As Point
 In ap
            Console.WriteLine(p)
        Next

    End Sub

    Public Shared Function
 PointFToPoint(ByVal pf As PointF) _
        As Point

        Return New Point(CInt(pf.X), CInt(pf.Y))
    End Function
End Class

' This code example produces the following output:
'
'{X=27.8, Y=32.62}
'{X=99.3, Y=147.273}
'{X=7.5, Y=1412.2}
'
'{X=28,Y=33}
'{X=99,Y=147}
'{X=8,Y=1412}
using System;
using System.Drawing;
using System.Collections.Generic;

public class Example
{
    public static void Main()
    {
        PointF[] apf = {
            new PointF(27.8F, 32.62F),
            new PointF(99.3F, 147.273F),
            new PointF(7.5F, 1412.2F) };

        Console.WriteLine();
        foreach( PointF p in apf )
        {
            Console.WriteLine(p);
        }

        Point[] ap = Array.ConvertAll(apf, 
            new Converter<PointF, Point>(PointFToPoint));

        Console.WriteLine();
        foreach( Point p in ap )
        {
            Console.WriteLine(p);
        }
    }

    public static Point PointFToPoint(PointF
 pf)
    {
        return new Point(((int)
 pf.X), ((int) pf.Y));
    }
}

/* This code example produces the following output:

{X=27.8, Y=32.62}
{X=99.3, Y=147.273}
{X=7.5, Y=1412.2}

{X=27,Y=32}
{X=99,Y=147}
{X=7,Y=1412}
 */

例 2

PointF 構造体Point 構造体変換する PointFToPoint という名前のメソッド定義するコード例次に示します。この例では、次に PointF 構造体List作成しConverter<PointF, Point> デリゲート (Visual Basic では Converter(Of PointF, Point)) を作成して PointFToPoint メソッド表し、そのデリゲートConvertAll メソッド渡しますConvertAll メソッドは、入力リスト各要素PointFToPoint メソッド渡し変換され要素Point 構造体新しリスト格納します両方リスト表示されます。

Imports System
Imports System.Drawing
Imports System.Collections.Generic

Public Class Example

    Public Shared Sub Main()

        Dim lpf As New List(Of
 PointF)

        lpf.Add(New PointF(27.8, 32.62))
        lpf.Add(New PointF(99.3, 147.273))
        lpf.Add(New PointF(7.5, 1412.2))

        Console.WriteLine()
        For Each p As PointF
 In lpf
            Console.WriteLine(p)
        Next

        Dim lp As List(Of
 Point) = lpf.ConvertAll( _
            New Converter(Of PointF, Point)(AddressOf
 PointFToPoint))

        Console.WriteLine()
        For Each p As Point
 In lp
            Console.WriteLine(p)
        Next

    End Sub

    Public Shared Function
 PointFToPoint(ByVal pf As PointF) _
        As Point

        Return New Point(CInt(pf.X), CInt(pf.Y))
    End Function
End Class

' This code example produces the following output:
'
'{X=27.8, Y=32.62}
'{X=99.3, Y=147.273}
'{X=7.5, Y=1412.2}
'
'{X=28,Y=33}
'{X=99,Y=147}
'{X=8,Y=1412}
using System;
using System.Drawing;
using System.Collections.Generic;

public class Example
{
    public static void Main()
    {
        List<PointF> lpf = new List<PointF>();

        lpf.Add(new PointF(27.8F, 32.62F));
        lpf.Add(new PointF(99.3F, 147.273F));
        lpf.Add(new PointF(7.5F, 1412.2F));

        Console.WriteLine();
        foreach( PointF p in lpf )
        {
            Console.WriteLine(p);
        }

        List<Point> lp = lpf.ConvertAll( 
            new Converter<PointF, Point>(PointFToPoint));

        Console.WriteLine();
        foreach( Point p in lp )
        {
            Console.WriteLine(p);
        }
    }

    public static Point PointFToPoint(PointF
 pf)
    {
        return new Point(((int)
 pf.X), ((int) pf.Y));
    }
}

/* This code example produces the following output:

{X=27.8, Y=32.62}
{X=99.3, Y=147.273}
{X=7.5, Y=1412.2}

{X=27,Y=32}
{X=99,Y=147}
{X=7,Y=1412}
 */
#using <System.Drawing.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::Collections::Generic;

Point PointFToPoint(PointF pf)
{
    return Point((int) pf.X, (int)
 pf.Y);
};

void main()
{
    List<PointF>^ lpf = gcnew List<PointF>();

    lpf->Add(PointF(27.8F, 32.62F));
    lpf->Add(PointF(99.3F, 147.273F));
    lpf->Add(PointF(7.5F, 1412.2F));

    Console::WriteLine();
    for each(PointF p in lpf)
    {
        Console::WriteLine(p);
    }

    List<Point>^ lp = 
        lpf->ConvertAll<Point>(
            gcnew Converter<PointF, Point>(PointFToPoint)
        );

    Console::WriteLine();
    for each(Point p in lp)
    {
        Console::WriteLine(p);
    }
}

/* This code example produces the following output:

{X=27.8, Y=32.62}
{X=99.3, Y=147.273}
{X=7.5, Y=1412.2}

{X=27,Y=32}
{X=99,Y=147}
{X=7,Y=1412}
 */
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



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

辞書ショートカット

すべての辞書の索引

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

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

   

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



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

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

©2024 GRAS Group, Inc.RSS