When is it useful to define your own delegates instead of using the generics?
- by Carlos
I've been going through some old code, where I came across some custom defined delegates, which are used thus:
private delegate void ListenDelegate(UdpClient listener, bool multicast);
private void ListenOn(UdpClient listener, bool multicast)
{
new ListenDelegate(_ListenLoop).BeginInvoke(listener, multicast, null, null);
}
With some of the new .NET framework versions, you can do the following:
private void ListenOn(UdpClient listener, bool multicast)
{
new Action<UdpClient, bool>(_ListenLoop).BeginInvoke(listener, multicast, null, null);
}
This ought to be exactly the same. Is there any point in defining your own delegates, when the generic delegates seem to do the same job with less space? Or have I missed something about the generics that makes them not equivalent?