Share via


Array.ForEach<T> Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

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

Syntax

'Declaration
Public Shared Sub ForEach(Of T) ( _
    array As T(), _
    action As Action(Of T) _
)
public static void ForEach<T>(
    T[] array,
    Action<T> action
)

Type Parameters

  • T
    The type of the elements of the array.

Parameters

  • array
    Type: array<T[]
    The one-dimensional, zero-based Array on whose elements the action is to be performed.

Exceptions

Exception Condition
ArgumentNullException

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

-or-

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

Remarks

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.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.