Sunday 3 December 2017

C# Program to Combine Two Delegates


Code:

using System;
delegate void dele(string s);
class TestClass

    static void Good(string s)
    {
        System.Console.WriteLine("  Good, {0}!", s);
    }

    static void Morning(string s)
    {
        System.Console.WriteLine("  Morning, {0}!", s);
    }

    static void Main()
    {
        dele firstdel, secondDel, multiDel, multiMinusfirstdel;
        firstdel = Good;
        secondDel = Morning; 
        multiDel = firstdel + secondDel;
        multiMinusfirstdel = multiDel - firstdel;
        Console.WriteLine("Invoking delegate firstdel:");
        firstdel("A");
        Console.WriteLine("Invoking delegate secondDel:");
        secondDel("B");
        Console.WriteLine("Invoking delegate multiDel:");
        multiDel("C");
        Console.WriteLine("Invoking delegate multiMinusfirstdel:");
        multiMinusfirstdel("D");
        Console.ReadLine();
    }
}



Output:

Invoking delegate firstDel:
  Good, A!
Invoking delegate SecondDel:
  Morning, B!
Invoking delegate multiDel:
  Good, C!
  Morning, C!
Invoking delegate multiMinusFirstDel:
  Morning, D!



More C# Programs:



















100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...