What is delegates & multicast delegate?

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


Please Help Members By Posting Answers For Below Questions

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?

546


What are annotations in c#?

521


What is the xml document structure?

469


List down the access modifiers available in c#?

479


What is the console on a mac?

471






Is c# difficult to learn?

480


Explain how obfuscator works in .net

547


What are c# types?

518


How to add controls dynamically to the form using c#.net.

469


Explain the difference between and xml documentation tag?

497


What does public mean in c#?

513


What is delegates and events?

468


what is IDisposal interface

671


What do you mean by parsing and how to parse a date time string in c#?

517


What operator means?

484