Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
Previous Versions
.NET Framework 2.0
System
Array Class
Array Methods
 ForEach Generic Method
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
.NET Framework Class Library
Array.ForEach Generic Method

Note: This method is new in the .NET Framework version 2.0.

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

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

Visual Basic (Declaration)
Public Shared Sub ForEach(Of T) ( _
    array As T(), _
    action As Action(Of T) _
)
Visual Basic (Usage)
Dim array As T()
Dim action As Action(Of T)

Array.ForEach(array, action)
C#
public static void ForEach<T> (
    T[] array,
    Action<T> action
)
C++
public:
generic<typename T>
static void ForEach (
    array<T>^ array, 
    Action<T>^ action
)
J#
J# supports the use of generic types and methods, but not the declaration of new ones.
JScript
JScript does not support generic types and methods.

Type Parameters

T

The type of the elements of the array.

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 typeCondition

ArgumentNullException

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

-or-

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

The Action 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.

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

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker