I’ve been playing with HttpWebRequests lately, and in the tutorials they always do:
IAsyncResult result = request.BeginGetResponse(
new AsyncCallback(UpdateItem),state);
But new AsyncCallback doesn’t seem to be necesary. If UpdateItem has the right signature, then there doesn’t seem to be a problem. So why do people include it? Does it do anything at all?
It’s the same thing, mostly (there are a few overload rules to think about, although not in this simple example). But in previous versions of C#, there wasn’t any delegate type inference. So the tutorial was either (a) written before delegate type inference was available, or (b) they wanted to be verbose for explanation purposes.
Here’s a summary of a few of the different ways you can take advantage of delegate type inferencing: