Try invoking a null delegate - CSharp Custom Type

CSharp examples for Custom Type:delegate

Description

Try invoking a null delegate

Demo Code



using System;/*from  w w w  . ja v  a 2  s  .  co  m*/
using System.Collections.Generic;
delegate int HandleTwo(int n, int m);
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" };

        try
        {
            int result4 = Multiply(2, 3, null);
        }
        catch (ArgumentNullException e)
        {
            Console.WriteLine(e.Message);
        }

    }
    static int Multiply(int x, int y, HandleTwo proc)
    {
        if (proc == null)
        {
            throw new ArgumentNullException("Null delegate passed.");
        }
        return proc(x, y);
    }
}

Result


Related Tutorials