When is it useful to define your own delegates instead of using the generics?

Posted by Carlos on Stack Overflow See other posts from Stack Overflow or by Carlos
Published on 2010-05-20T12:08:17Z Indexed on 2010/05/20 12:10 UTC
Read the original article Hit count: 197

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about delegates