Repository navigation
EN CSharp Events
Codex edited this page Oct 11, 2026
·
2 revisions
Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
event allows handlers to be signed via += and removed via -=. The event is raised by the type that declared it. An externally owned handler holds the subscriber, so the subscription must be terminated when it is no longer needed.
Save this example separately as Example.cs. Run it independently of the other examples on this page.
Example.cs:
// PROJECT-EXAMPLE
var source = new Source();
source.Changed += () => System.Console.WriteLine("Changed");
source.Raise();
class Source { public event System.Action? Changed; public void Raise() => Changed?.Invoke(); }Result:
Changed
sealed class Progress
{
public event Action<int>? Changed;
public void Report(int value) => Changed?.Invoke(value);
}
var progress = new Progress();
Action<int> handler = value => UO.Print($"Progress={value}");
progress.Changed += handler;
progress.Report(1);
progress.Changed -= handler;sealed class Signal
{
public event EventHandler? Ready;
public void Raise() => Ready?.Invoke(this, EventArgs.Empty);
}
var signal = new Signal();
signal.Ready += (_, _) => UO.Print("Ready");
signal.Raise();These examples describe events of their own C#-classes. Game events are provided separately by API host; their names, arguments, and lifecycles must match the specific event documentation.
Official documentation: Events and Handlers - Microsoft Learn.
ClassicUO — Bad Newbie & C# Scripts IDE