using System;
using System.Collections.Generic;
class GFG {
public static void Main()
{
try {
int[] myArr = { 2, 3, 4, 5 };
Console.Write("Initial Array: ");
PrintIndexAndValues(myArr);
Action<int> action = new Action<int>(SetSquares);
Array.ForEach(myArr, action);
}
catch (ArgumentNullException e) {
Console.Write("Exception Thrown: ");
Console.Write("{0}", e.GetType(), e.Message);
}
}
public static void PrintIndexAndValues(int[] myArr)
{
for (int i = 0; i < myArr.Length; i++) {
Console.Write("{0} ", myArr[i]);
}
Console.WriteLine();
Console.WriteLine();
}
private static void SetSquares(int val)
{
Console.WriteLine("{0} squared = {1}",
val, val * val);
}
}