Practice mode C#

What does the event keyword add when applied to a delegate field in a C# class?

Correct answer C. Outside code can only subscribe with += and unsubscribe with -=, not invoke or replace it

Explanation

Declaring public event EventHandler Clicked; wraps the delegate so that only the declaring class can raise it or assign it directly. External subscribers can only add and remove handlers with += and -=. With a plain public delegate field, any code could invoke it or wipe out other subscribers with =. The event is typically raised with Clicked?.Invoke(this, EventArgs.Empty).

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.