A generic delegate. : Generic delegate : Generic C# Examples


C# Examples » Generic » Generic delegate »

 

A generic delegate.









    
using  System;    
    
delegate  T  SomeOp<T>(T  v);    
    
class  MainClass  {    
    static  int  sum(int  v)  {  
        return  v;  
    }  
  
    static  string  reflect(string  str)  {  
        return  str;  
    }  
            
    public  static  void  Main()  {      
        SomeOp<int>  intDel  =  sum;    
        Console.WriteLine(intDel(3));  
  
        SomeOp<string>  strDel  =  reflect;    
        Console.WriteLine(strDel("Hello"));  
    }    
}
    
   
  
   



Output

3
Hello


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Generic
» Generic delegate