Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

C#, difference between event and delegate without keyword event, I can't understand

C#.
If you were asked on a technical interview for a job this question, how would you answer it?

Tell me about the difference of these cases:

1)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

public class SampleClass
{
    public System.Action a;
}
public class SampleClass
{
    public event System.Action a;
}

>Solution :

Events in C# are a mechanism that classes use to send notifications or messages to other classes. They are a specialized delegate type that we use to notify other classes when something they listen to happens. Events are a vital part of many applications, and a perfect way to decouple and create flexible and extendable applications.

A delegate is a reference to a method. If we call a delegate, the referenced method is called instead. Delegates have all the necessary information to call a method or group of methods with a specific signature and return type. We can pass a delegate as an argument to other methods or we can store it in a structure or a class.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading