Array.ConvertAll(TInput[], Converter<TInput, TOutput>) Method is used to convert an array of one type to an array of another type.
Syntax:
public static TOutput[] ConvertAll<TInput,TOutput> (TInput[] array,
Converter<TInput,TOutput> converter);
Here,
TInput and
TOutput is the source array and target array respectively.
Parameters:
array: It is the one-dimensional, zero-based Array to convert to a target type.
converter: It is a Converter that converts each element from one type to another type.
Return Value: This method returns an array of the target type containing the converted elements from the source array.
Exception: This method throws
ArgumentNullException if the
array is null or
converter is null.
Below programs illustrate the use of
Array.ConvertAll(TInput[], Converter<TInput, TOutput>) Method
Example 1:
Output:
Initial Array:
10
20
30
40
Converted Array:
10
20
30
40
Example 2: