Skip to main content

Posts

Showing posts with the label delegate in c# with example

What are Generic Delegates, Types and Examples in C#?

Microsoft provides three ready-made generics delegate . This is call shorter and sweeter delegate. This to minimize the code complexity of the apps. 1.       Func < input, output > 2.       Action < inputParameter > 3.       Predicate < inputParameter > Func <input, output > Delegate :- The Func <input, output> generic delegate is use, when you need to some input parameter and then return some output. The example for Func generic delegate as given below, namespace  GenericDelegate {      public   class   Delegates     {          static   void  Main( string [] args)         {              // int is a input parameter and double is output parameter  ...

Multicast Delegate Example in C#.Net

What are Multicast delegate, type and use? The multicast   delegate is hold the references of more than one methods within the delegate object using the (+=) operator. 1.       Delegate is added using the (+=) operator.  2.       Delegate is removed using the (-=) operator.  Example for Multicast Delegate as following, using  System; using  System.Collections.Generic; using  System.Linq; using  System.Text; namespace  MulticastDelegateExample {      public   delegate   int   MulticastDelegateName ( int  num1,  int  num2);      public   class   MulticastClass     {          public   static   int  Add( int  num1,  int  num2)         {     ...

Mapped Delegates static and instance methods

This is example is used for mapped both the static and instance methods in the Delegates using ASP.Net C#. using  System; using  System.Collections.Generic; using  System.Linq; using  System.Text; namespace  Delegates {      delegate   void   MyDelegate ();      public   class   MyClass     {          public   void  InstanceMethods()         {              Console .WriteLine( "Instance method call" );         }          static   public   void  StaticMethods()         {              Console .WriteLine( "Static method call"...