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
I have 3 overloaded constructors in my class. In order to avoid making instance of the class do I need to make all constructors to private?
What are annotations in c#?
What is the xml document structure?
List down the access modifiers available in c#?
What is the console on a mac?
Is c# difficult to learn?
Explain how obfuscator works in .net
What are c# types?
How to add controls dynamically to the form using c#.net.
Explain the difference between and xml documentation tag?
What does public mean in c#?
What is delegates and events?
what is IDisposal interface
What do you mean by parsing and how to parse a date time string in c#?
What operator means?