Repository navigation
KO CSharp Keyword event
Codex edited this page Oct 11, 2026
·
2 revisions
Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
외부 코드가 +=로 구독하고 -=로 구독 취소하는 메시지를 선언합니다. 통화는 일반적으로 소유자 유형에 속합니다.
이 예제를 Example.cs로 따로 저장하고 이 페이지의 다른 예제와 독립적으로 실행하세요.
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(); }결과:
Changed
public event Action? Changed;using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
public static class Program
{
public static async Task Main(string[] args)
{
Notifier source = new();
Action<string> handler = text => Console.WriteLine(text);
source.Message += handler; source.Publish("Ready");
source.Message -= handler;
}
}
public class Notifier { public event Action<string>? Message; public void Publish(string text) { Message?.Invoke(text); } }using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
public static class Program
{
public static async Task Main(string[] args)
{
Notifier source = new();
Action handler = () => Console.WriteLine("Changed");
source.Changed += handler; source.Publish(); source.Changed -= handler; source.Publish();
}
}
public class Notifier { private Action? handlers; public event Action Changed { add { handlers += value; } remove { handlers -= value; } } public void Publish() { handlers?.Invoke(); } }공식 출처: Microsoft 학습.
ClassicUO — Bad Newbie & C# Scripts IDE