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

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

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

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

ある型の配列を別の型の配列に変換します。

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

Public Shared Function ConvertAll(Of
 TInput, TOutput) ( _
    array As TInput(), _
    converter As Converter(Of TInput, TOutput)
 _
) As TOutput()
Dim array As TInput()
Dim converter As Converter(Of
 TInput, TOutput)
Dim returnValue As TOutput()

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

型パラメータ

TInput

元の配列要素の型。

TOutput

変換後の配列要素の型。

パラメータ

array

変換元となる、インデックス番号が 0 から始まる 1 次元 Array。

converter

各要素の型を変換するための Converter。

戻り値
要素の型を変換した後の配列。

例外例外
例外の種類条件

ArgumentNullException

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

または

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

解説解説

Converter は、オブジェクトを別の型に変換するメソッドのデリゲートです。array の要素が、それぞれ Converter に渡され、変換後の要素が新しい配列に格納されます。

元の array は変更されません。

このメソッドは O(n) 操作です。ここで、n は array の Length です。

使用例使用例

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



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

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

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

   

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



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

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

©2026 GRAS Group, Inc.RSS