Do action on each element of the specified array in CSharp
Description
The following code shows how to do action on each element of the specified array.
Example
using System;/*from ww w . j ava 2s . c o m*/
public class SamplesArray
{
public static void Main()
{
int[] intArray = new int[] {2, 3, 4};
Action<int> action = new Action<int>(ShowSquares);
Array.ForEach(intArray, action);
}
private static void ShowSquares(int val)
{
Console.WriteLine("{0:d} squared = {1:d}", val, val*val);
}
}
The code above generates the following result.