Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Practical use of interface events [closed]

What is a good example of the power of interface events (declaring events inside interface)?

Most of the times I have seen only public abstract methods inside interface.

like image 578
user160677 Avatar asked Nov 17 '09 01:11

user160677


People also ask

Can an interface have events?

An interface can declare an event. The following example shows how to implement interface events in a class. Basically the rules are the same as when you implement any interface method or property.

CAN interfaces have events C#?

An interface can be created to define a contract containing members that classes that implement it must provide. Interfaces can define events, sometimes leading to classes that implement several interfaces being required to declare an event name twice.

What is advantage of interface in C#?

One of the major advantages of Interface in C# is a better alternative to implement multiple inheritances. The interface enables the plug-and-play method. Complete Abstraction can be achieved by the implementation of Interface. Along with making our code easy to maintain, concept loose coupling can be achieved.

What is an interface in C# with example?

In C#, an interface is similar to abstract class. However, unlike abstract classes, all methods of an interface are fully abstract (method without body). We use the interface keyword to create an interface. For example, interface IPolygon { // method without body void calculateArea(); }


1 Answers

I used events to signal when a serial port received data.

Here is my interface.

public interface ISerialPortWatcher {     event EventHandler<ReceivedDataEventArgs> ReceivedData;     event EventHandler StartedListening;     event EventHandler StoppedListening;      SerialPortSettings PortOptions { set; }      bool Listening { get; set; }     void Stop();     void Start(); }  public class ReceivedDataEventArgs : EventArgs {     public ReceivedDataEventArgs(string data)     {         Data = data;     }     public string Data { get; private set; } } 
like image 184
Daniel A. White Avatar answered Sep 23 '22 05:09

Daniel A. White