Do action on each element of the specified array in CSharp

Description

The following code shows how to do action on each element of the specified array.

Example


using System;/*from  ww  w .  j  ava  2s  . c o m*/

public class SamplesArray
{
    public static void Main()
    {
        int[] intArray = new int[] {2, 3, 4};

        Action<int> action = new Action<int>(ShowSquares);

        Array.ForEach(intArray, action);
    }

    private static void ShowSquares(int val)
    {
        Console.WriteLine("{0:d} squared = {1:d}", val, val*val);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var