Generics and Delegates : Generic delegate « Generics « C# / C Sharp






Generics and Delegates

 

using System;

public delegate void DelegateClass(int data);

public class Starter {
    public static void Main() {
        DelegateClass del1 = MethodA<int>;
        del1(5);
        DelegateClass del2 = MethodA;
        del1(10); // inferred
    }
    public static void MethodA<T>(T data) {
        Console.WriteLine("MethodA ({0})", data);
    }
}

 








Related examples in the same category

1.A simple generic delegateA simple generic delegate
2.Convert event to use generic delegateConvert event to use generic delegate
3.Generic Delegate and non-generic delegate
4.a generic delegate being initialized with a normal method
5.Generic Anonymous Methods