Doing the do-to-each problem using raw delegates, anonymous methods, and lambdas. - CSharp Custom Type

CSharp examples for Custom Type:delegate

Description

Doing the do-to-each problem using raw delegates, anonymous methods, and lambdas.

Demo Code



using System;/*from w w w .j a  v a  2s  .  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" };

        int firstNumberGreaterThanFive = numbers.Find(NumberGT5);
        Console.WriteLine(firstNumberGreaterThanFive.ToString());
    }
    // A method conforming to the Predicate<T> delegate signature.
    static bool NumberGT5(int num)
    {
        return num > 5;
    }
}

Result


Related Tutorials