C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Lambda: The second argument to Array.ConvertAll is a lambda expression. The lambda returns the ToString() method result on the element.
Generic Class, MethodToStringC# program that uses Array.ConvertAll method
using System;
class Program
{
static void Main()
{
// Integer array of 3 values.
int[] array1 = new int[3];
array1[0] = 4;
array1[1] = 5;
array1[2] = 6;
// Use ConvertAll to convert integer array to string array.
string[] array2 = Array.ConvertAll(array1,
element => element.ToString());
// Write string array.
Console.WriteLine(string.Join(",", array2));
}
}
Output
4,5,6
Note: The ConvertAll method allocates a new array and then places the result of the converter method into each corresponding element slot.