Skip to content

Events and subscription

EventDeclaration = "event" identifier ":" DelegateType .
RaiseStatement = "raise" identifier "(" [ ArgumentList ] ")" .
Subscription = Expression ( "+=" | "-=" ) DelegateExpression .

Events are field-style members on classes and interfaces; their type shall be a delegate. A class event emits a private backing delegate, add_/remove_ accessors, and an EventDefinition. An interface event emits abstract accessors and its EventDefinition. += and -= invoke those accessors for E# and imported CLR events alike.

raise Name(args) is valid only within the declaring class. It snapshots the current delegate and invokes that snapshot if non-null, so raising with no subscribers is a no-op. Every subscribed handler is invoked through normal multicast delegate order.

class Counter {
pub event Changed: Action<int>
var total: int
func add(n: int) { self.total += n raise Changed(self.total) }
}