Delegate with reference paramemters : Delegate : Delegate C# Examples


C# Examples » Delegate » Delegate »

 

Delegate with reference paramemters









    
using  System;

delegate  void  FunctionToCall(ref  int  X);

class  MainClass
{
      public  static  void  Add2(ref  int  x)  {  
              x  +=  2;  
      }
      
      public  static  void  Add3(ref  int  x)  {  
              x  +=  3;  
      }

      static  void  Main(string[]  args)
      {
            FunctionToCall  functionDelegate  =  Add2;
            functionDelegate  +=  Add3;
            functionDelegate  +=  Add2;

            int  x  =  5;
            functionDelegate(ref  x);

            Console.WriteLine("Value:  {0}",  x);
      }
}
    
   
  
   



Output

Value: 12


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Delegate
» Delegate