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

arraynull 参照 (Visual Basic では Nothing) です。

または

converternull 参照 (Visual Basic では Nothing) です。

解説解説

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

元の array変更されません。

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

使用例使用例

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


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

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

辞書ショートカット

すべての辞書の索引

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

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

   

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



Array.ConvertAll ジェネリック メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS