KO CSharp Keyword add - 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();
System.Action handler = () => { };
source.Changed += handler;
source.Changed -= handler;
class Source
{
public event System.Action Changed { add { System.Console.WriteLine("Add"); } remove { System.Console.WriteLine("Remove"); } }
}๊ฒฐ๊ณผ:
Add
Remove
event Action Changed { add { ... value ... } remove { ... } }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(); } }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)
{
Signal signal = new();
Action handler = () => Console.WriteLine("Signal");
signal.Fired += handler; signal.Fire(); signal.Fired -= handler;
}
}
public class Signal { private readonly List<Action> handlers = []; public event Action Fired { add { handlers.Add(value); } remove { handlers.Remove(value); } } public void Fire() { foreach (Action handler in handlers.ToArray()) handler(); } }๊ณต์ ์ถ์ฒ: Microsoft ํ์ต.