Do an action on the list using an anonymous method - CSharp Custom Type

CSharp examples for Custom Type:Anonymous Types

Description

Do an action on the list using an anonymous method

Demo Code




using System;//from w ww.  j a  v  a  2  s .c o m
using System.Collections.Generic;
delegate void DoIt(string msg);
class Program
{
    static void Main(string[] args)
    {
        List<int> numbers = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
        int[] numArray = numbers.ToArray();
        List<string> words = new List<string> { "one", "two", "three", "four", "five" };

        numbers.ForEach(delegate (int num) { Console.WriteLine("Number before {0} is {1}", num, num - 1); });
    }
}

Result


Related Tutorials