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 extension method in c sharp?
Do unused Namespaces in c# affect run-time performance?
What’s a strong name?
3. Use layered architecture for coding. s.no name description 1 abc xxxxxxxxx 2 abc xxxxxxxxx 3 4 5 6 7 8 Select all Clear all Add Delete Name Description Save close
What is the difference between Static, Const and read only?
What is data annotation in c#?
What is the difference between field and variable in c#?
Is string mutable in c#?
What is the difference between the debug class and trace class? Documentation looks the same.
What is dto c#?
Explain briefly the difference between value type and reference type?
What is difference between write and writeline in c#?
Why do you need boxing in c#?
what is the meaning of Object lifetime in OOPS
Explain the advantage of using system.text.stringbuilder over system.string?