Array.ConvertAll ジェネリック メソッド
アセンブリ: 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 )
パラメータ
戻り値
要素の型を変換した後の配列。



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} */

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- Array.ConvertAll ジェネリック メソッドのページへのリンク