C# Array ConvertAll
Description
Array ConvertAll
converts
an array of one type to an array of another type.
Syntax
Array.ConvertAll
has the following syntax.
public static TOutput[] ConvertAll<TInput, TOutput>(
TInput[] array,
Converter<TInput, TOutput> converter
)
Parameters
Array.ConvertAll
has the following parameters.
TInput
- The type of the elements of the source array.TOutput
- The type of the elements of the target array.array
- The one-dimensional, zero-based Array to convert to a target type.converter
- A Converter that converts each element from one type to another type.
Returns
Array.ConvertAll
method returns
Example
The following code example defines a method named PointFToPoint that converts a PointF structure to a Point structure.
using System;//from www . jav a 2 s . c o m
using System.Drawing;
using System.Collections.Generic;
public class Example
{
public static void Main()
{
PointF[] apf = {
new PointF(7.8F, 3.2F),
new PointF(9.3F, 7.73F),
new PointF(7.5F, 2.2F) };
Point[] ap = Array.ConvertAll(apf, new Converter<PointF, Point>(PointFToPoint));
foreach( Point p in ap )
{
Console.WriteLine(p);
}
}
public static Point PointFToPoint(PointF pf)
{
return new Point(((int) pf.X), ((int) pf.Y));
}
}
The code above generates the following result.