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"));
}
}
Related examples in the same category