You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.1 KiB
Plaintext

/*
* C# Program to Combine Two Delegates
*/
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();
}
}
/*
Invoking delegate firstDel:
Good, A!
Invoking delegate SecondDel:
Morning, B!
Invoking delegate multiDel:
Good, C!
Morning, C!
Invoking delegate multiMinusFirstDel:
Morning, D!