A simple delegate example. : Delegate : Delegate C# Examples


C# Examples » Delegate » Delegate »

 

A simple delegate example.









    
using  System;  
  
delegate  string  StrMod(string  str);  
  
class  MainClass  {  

    static  string  replaceSpaces(string  a)  {  
        Console.WriteLine("replaceSpaces");  
        return  a;  
    }    
  
    static  string  removeSpaces(string  a)  {  
        Console.WriteLine("removeSpaces");  
        return  a;  
    }    
  
    static  string  reverse(string  a)  {  
        Console.WriteLine("reverseSpaces");  
        return  a;  
    }  
          
    public  static  void  Main()  {    
        StrMod  strOp  =  new  StrMod(replaceSpaces);  
        string  str;  
  
        str  =  strOp("This  is  a  test.");  
            
        strOp  =  new  StrMod(removeSpaces);  
        str  =  strOp("This  is  a  test.");  
  
        strOp  =  new  StrMod(reverse);  
        str  =  strOp("This  is  a  test.");  
    }  
}
    
   
  
   



Output

replaceSpaces
removeSpaces
reverseSpaces


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Delegate
» Delegate