Can someone explain to me how custom event accessor works? I have read a couple of articles on google but still could not understand. Also, when to use it?
I have the following code snippet from my project. If someone can explain this to me it would be really great.
private event Action<int> ActivityChanged = delegate {};
event Action<int> IActivityFacade.ActivityChanged
{
add
{
ActivityChanged += value;
value(GetSelectedActivity());
}
remove { ActivityChanged -= value; }
}
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.
Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.
C is an imperative procedural language supporting structured programming, lexical variable scope, and recursion, with a static type system. It was designed to be compiled to provide low-level access to memory and language constructs that map efficiently to machine instructions, all with minimal runtime support.
Without knowing exactly what part of the existing documentation and other references regarding custom event accessors it is specifically that you don't understand, it's impossible to know for sure what answer you're looking for.
A C# event
is simply an add
and a remove
method (similar to a property's get
and set
methods). The compiler provides a default implementation for these methods, but if you have custom behavior you want to implement yourself, you can write the methods yourself. In your example, which is not thread-safe by the way, the custom accessors are apparently there so that a newly subscribed delegate is invoked as soon as it's added.
If you need more details than that, please improve the question so that it's clear what it is specifically about custom event accessors that you are having trouble understanding. Be sure to explain exactly what you do understand and what documentation you've already referenced, so that we can avoid excessively long answers that waste time on aspects you already know about.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With