This documentation is archived and is not being maintained.

Array.ForEach(T) Method

Performs the specified action on each element of the specified array.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

JScript does not support generic types or methods.

Type Parameters

T

The type of the elements of the array.

Parameters

array
Type: T[]

The one-dimensional, zero-based Array on whose elements the action is to be performed.

action
Type: System.Action(T)

The Action(T) to perform on each element of array.

ExceptionCondition
ArgumentNullException

array is a null reference (Nothing in Visual Basic).

-or-

action is a null reference (Nothing in Visual Basic).

The Action(T) is a delegate to a method that performs an action on the object passed to it. The elements of array are individually passed to the Action(T).

This method is an O(n) operation, where n is the Length of array.

The following example shows how to use ForEach(T) to display the squares of each element in an integer array.

No code example is currently available or this language may not be supported.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Show: