A simple generic delegate : Generic delegate : Generics C# Source Code


Custom Search

C# Source Code » Generics » Generic delegate »

 

A simple generic delegate









    


using System;

// Declare a generic delegate.
delegate T GenericDelegate<T>(T v);

class GenDelegateDemo {
  static int sum(int v) {
    int result = 0;
    for(int i=v; i>0; i--)
      result += i;

    return result;
  }

  static string reflect(string str) {
    string result = "";

    foreach(char ch in str)
      result = ch + result;

    return result;
  }

  public static void Main() {
    GenericDelegate<int> intDel = sum;
    Console.WriteLine(intDel(3));

    GenericDelegate<string> strDel = reflect;
    Console.WriteLine(strDel("Hello"));
  }
}
           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Generics
» Generic delegate