KO CSharp Keyword remove - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki

ะฃะบั€ะฐั—ะฝััŒะบะฐ ยท ะ ัƒััะบะธะน ยท English ยท Deutsch ยท Franรงais ยท Italiano ยท Espaรฑol ยท ็น้ซ”ไธญๆ–‡ ยท ๆ—ฅๆœฌ่ชž ยท ํ•œ๊ตญ์–ด

C#: remove

ํ•ธ๋“œ๋ถ C# ยท ์‹ค์šฉ ๊ฐ€์ด๋“œ

๊ตฌ๋… ์ทจ์†Œ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ์ž…๋‹ˆ๋‹ค. ๊ฐ’์—๋Š” ์ฒ˜๋ฆฌ๊ธฐ ๋Œ€๋ฆฌ์ž๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

๊ฐ„๋‹จํ•œ ์˜ˆ์ œ (Example.cs)

์ด ์˜ˆ์ œ๋ฅผ 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 { ... } remove { ... value ... } }

์˜ˆ์‹œ 1: ๊ธฐ๋ณธ ํ˜•ํƒœ

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(); } }

์˜ˆ 2: ๋˜ ๋‹ค๋ฅธ ์‹ค์ œ ํ˜•์‹

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 ํ•™์Šต.

โš ๏ธ **GitHub.com Fallback** โš ๏ธ