Blog: API Design

How to mimic singlecast events in C#

January 12, 2015, (updated on February 13, 2015), Software Development

C# only supports multicast events and delegates. Even if you define a delegate property without the event keyword, it still remains multicasted: public class Foo { public Action MyEvent { get; set; } } var foo = new Foo(); foo.MyEvent += delegate { }; foo.MyEvent += delegate { }; The only difference between a regular property with a delegate type and an event property are: The event property can only be invoked by its class, the delegate in the regular property can also be invoked from outside (which may not be desired) Accessing and assigning an event property is only […] Read more...

Tags: , , ,

  Page 1 of 1