KO CSharp Keyword event - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki
ะฃะบัะฐัะฝััะบะฐ ยท ะ ัััะบะธะน ยท English ยท Deutsch ยท Franรงais ยท Italiano ยท Espaรฑol ยท ็น้ซไธญๆ ยท ๆฅๆฌ่ช ยท ํ๊ตญ์ด
ํธ๋๋ถ C# ยท ์ค์ฉ ๊ฐ์ด๋
์ธ๋ถ ์ฝ๋๊ฐ +=๋ก ๊ตฌ๋ ํ๊ณ -=๋ก ๊ตฌ๋ ์ทจ์ํ๋ ๋ฉ์์ง๋ฅผ ์ ์ธํฉ๋๋ค. ํตํ๋ ์ผ๋ฐ์ ์ผ๋ก ์์ ์ ์ ํ์ ์ํฉ๋๋ค.
์ด ์์ ๋ฅผ 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 ํ์ต.