![]() |
VOOZH | about |
Array.ForEach(T[], Action<T>) Method is used to perform the specified action on each element of the specified array.
Syntax:
public static void ForEach<T> (T[] array, Action<T> action);
Parameters:
array: The one-dimensional, zero-based Array on whose elements the action is to be performed.
action: The Action to perform on each element of array.
Exception: This method throws ArgumentNullException array is null or action is null.
Below programs illustrate the use of Array.ForEach(T[], Action) Method:
Example 1:
Initial Array: 2 3 4 5 2 squared = 4 3 squared = 9 4 squared = 16 5 squared = 25
Example 2:
Trying to perform action on a null Array Exception Thrown: System.ArgumentNullException
Reference: