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

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

List.ConvertAll ジェネリック メソッド

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

現在の List の要素を別の型に変換し、変換された要素が格納されたリストを返します。

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

Public Function ConvertAll(Of
 TOutput) ( _
    converter As Converter(Of T, TOutput) _
) As List(Of TOutput)
Dim instance As List(Of
 T)
Dim converter As Converter(Of
 T, TOutput)
Dim returnValue As List(Of
 TOutput)

returnValue = instance.ConvertAll(converter)
public List<TOutput> ConvertAll<TOutput> (
    Converter<T,TOutput> converter
)
public:
generic<typename TOutput>
List<TOutput>^ ConvertAll (
    Converter<T, TOutput>^ converter
)
J# では、ジェネリックな型およびメソッドは使用できますが、新規に宣言することはできません。
JScript では、ジェネリックな型およびメソッドは使用できません。

パラメータ

converter

各要素の型を変換するための Converter デリゲート。

戻り値
現在の List の要素の型を変換した後の List。

例外例外
例外の種類条件

ArgumentNullException

converter が null 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

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}
 */
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

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

   

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



List.ConvertAll ジェネリック メソッドのページの著作権

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

©2026 GRAS Group, Inc.RSS