Answer Posted / neerajtyagi
delegate void Del(string s);
class TestClass
{
static void Hello(string s)
{
System.Console.WriteLine(" Hello, {0}!", s);
}
static void Goodbye(string s)
{
System.Console.WriteLine(" Goodbye, {0}!", s);
}
static void Main()
{
Del a, b, c, d;
// Create the delegate object a that references
// the method Hello:
a = Hello;
// Create the delegate object b that references
// the method Goodbye:
b = Goodbye;
// The two delegates, a and b, are composed to form
c:
c = a + b;
// Remove a from the composed delegate, leaving d,
// which calls only the method Goodbye:
d = c - a;
System.Console.WriteLine("Invoking delegate a:");
a("A");
System.Console.WriteLine("Invoking delegate b:");
b("B");
System.Console.WriteLine("Invoking delegate c:");
c("C");
System.Console.WriteLine("Invoking delegate d:");
d("D");
}
}
// Output will be
Invoking delegate a:
Hello, A!
Invoking delegate b:
Goodbye, B!
Invoking delegate c:
Hello, C!
Goodbye, C!
Invoking delegate d:
Goodbye, D!
Is This Answer Correct ? | 15 Yes | 2 No |
Post New Answer View All Answers
What is event delegate in c#?
Can hashtable have duplicate keys?
Write a program in C# for checking a given number is PRIME or not.
What is the max value of int32 in c#?
What basic steps are needed to display a simple report in crystal?
what is IDisposal interface,IComparable,IEquatable,IFormatable
Explain the difference between user control and custom control. Also, explain their use.
What is overriding in c#?
How more than one version of an assembly can keep in same place?
What is difference between c sharp and c#?
What Is A Multicast Delegate?
What’s thread.sleep() in threading ?
Define an abstract class?
Does unity use c++ or c#?
What are get and set in c#?