Return delegate from a method : Return delegate : Delegate C# Examples


C# Examples » Delegate » Return delegate »

 

Return delegate from a method









    
using  System;

public  delegate  void  MyDeleage();

public  class  MainClass
{
        public  static  MyDeleage[]  CreateDelegates()  {
                MyDeleage[]  delegates  =  new  MyDeleage[3];
                
                for(  int  i  =  0;  i  <  3;  ++i  )  {
                        delegates[i]  =  delegate  {
                                Console.WriteLine(  "Hi"  );  
                        };
                }
                return  delegates;
        }

        static  void  Main()  {
                MyDeleage[]  delegates  =  CreateDelegates();
                for(  int  i  =  0;  i  <  3;  ++i  )  {
                        delegates[i]();
                }
        }
}
    
   
  
   



Output

Hi
Hi
Hi


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Delegate
» Return delegate