A
A
Alexander Zaitsev2015-12-08 23:50:36
.NET
Alexander Zaitsev, 2015-12-08 23:50:36

Event is value or reference type in C#?

Event is value or reference type in C#? Justify your answer please.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Makarov, 2015-12-09
@nithrous

event is related to a delegate instance ( Stanislav Makarov : multicast ) as property is related to a field value.
event is syntactic sugar, a wrapper for add and remove methods, just as property is a wrapper for get and set methods.
So the question is incorrect since event is not a type.

S
Stanislav Makarov, 2015-12-09
@Nipheris

1) An event is the same delegate, only with a truncated interface for external calls (outside the class). Only the operations of adding and removing a handler get into the public interface of the class from the event. You can invoke an event delegate from within the class, but you cannot invoke it from outside the class (i.e. like this: button1.Clicked(new EventArgs(...)) );
2) Since we found out that the event is a delegate (multicast, moreover), then we go and make sure that the delegate is a reference type: https://msdn.microsoft.com/en-us/library/system.mu. ..
Exam on the nose? Successful submission!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question