dotnet / docs

This repository contains .NET Documentation.
https://learn.microsoft.com/dotnet
Creative Commons Attribution 4.0 International
4.21k stars 5.86k forks source link

Comment is wrong in the example #33077

Closed Soran-M closed 1 year ago

Soran-M commented 1 year ago

[Enter feedback here] Hello,

The word create in the 2 comments below are incorrect. The delegate has been already created ahead of these two statements. What is done here is they are initialized.

    // Create the delegate object hiDel that references the method Hello.
    hiDel = Hello;

    // Create the delegate object byeDel that references the method Goodbye.
    byeDel = Goodbye;

Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

svick commented 1 year ago

The comments are correct. The variable has been defined before, but the object is created here and only then is the variable initialized using that object.

Another way to see that is to replace the line with e.g. hiDel = new CustomDel(Hello);. This is equivalent to the shorter version, but more clearly shows that a CustomDel object is being created.

BillWagner commented 1 year ago

Based on the conversation, I've added this to the backlog as an enhancement, and added the "help wanted" label to the issue.

@svick 's suggestion would make the code and the explanation clearer. We'll make that change when we next update this article., or anyone can issue a PR and we'll merge it.

BartoszKlonowski commented 1 year ago

@BillWagner I would like to work on this - this is a minor change to made so I'll deliver the PR today.