What is Multicast Delegate? Explain it with example in C#?
are used to wrap and execute methods having the same signature as that
of the delegate. They wrap method calls and prevent exposing the actual
method name to the User.
Delegates have a very special feature which supports execution of multiple methods using a single delegate call. This is known as multicast delegate.
For a delegate you can define an invocation list and while calling the delegate, all the methods in its invocation list will be executed. You can add methods to the invocation list using += operator. You can also remove methods from the list using -= operator. The following example demonstrates usage of multicast delegate in C# by creating a delegate and executing two different methods using the same delegate:
void sampleDelegate(int data);
Output of this code will be:
is an even number
to our mailing list and receive new articles Note
: We never rent, trade, or sell my email lists to Visit
.NET Programming Tutorial Homepage ______________________________________________________
to our mailing list and receive new articles
: We never rent, trade, or sell my email lists to
Visit .NET Programming Tutorial Homepage
| Can you call a constructor from another constructor of the Class in .NET? | Difference between Response.Output.Write() method and Response.Write() method in .NET | How do you establish multiple inheritance in C#? | How do you introduce a ReadOnly property in C#? | How do you perform constructor overloading in C#? | Is catch(Exception) recommended to be used in .NET? | What are the different access modifiers available in C#? | What are the different ways of overloading in C#? | What are the members of stringbuilder class in C#? | What is Multicast Delegate? Explain it with example in C# | What is the difference between abstract class and interface in .NET? | What is the difference between Clone and CopyTo methods in .NET | What is the difference between const and readonly in .NET | What is the difference between directcast and ctype in .NET? | What is the difference between out and ref parameters in .NET | What is the difference between public assembly and private assembly in .NET | What is the difference between strong typing and weak typing in .NET? | What is the difference between Trace and Debug in .NET | What is the need for Abstract Factory Pattern in C#? | What is the need for Adapter Pattern in C# |
Amazon and the Amazon logo are trademarks of Amazon.com, Inc. or its affiliates.
Copyright - © 2004 - 2023 - All Rights Reserved.