KO CSharp Keyword volatile - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki
ะฃะบัะฐัะฝััะบะฐ ยท ะ ัััะบะธะน ยท English ยท Deutsch ยท Franรงais ยท Italiano ยท Espaรฑol ยท ็น้ซไธญๆ ยท ๆฅๆฌ่ช ยท ํ๊ตญ์ด
C#: volatile
ํธ๋๋ถ C# ยท ์ค์ฉ ๊ฐ์ด๋
์ค๋ ๋ ๊ฐ ํ๋์ ์ฝ๊ธฐ ๋ฐ ์ฐ๊ธฐ ๊ฐ์์ฑ ๊ท์น์ ์ ์ํฉ๋๋ค. counter++ ์์์ฑ ๊ฐ์ ๋ณตํฉ ์ฐ์ฐ์ ๋ง๋ค์ง ์์ต๋๋ค.
๊ฐ๋จํ ์์ (Example.cs)
์ด ์์ ๋ฅผ Example.cs๋ก ๋ฐ๋ก ์ ์ฅํ๊ณ ์ด ํ์ด์ง์ ๋ค๋ฅธ ์์ ์ ๋
๋ฆฝ์ ์ผ๋ก ์คํํ์ธ์.
Example.cs:
// PROJECT-EXAMPLE
System.Console.WriteLine(new State().Stopped);
class State { public volatile bool Stopped = false; }
๊ฒฐ๊ณผ:
False
ํต์ฌ๋ก
private volatile bool stopping;
์์ 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)
{
Worker worker = new();
await Task.Run(() => worker.Stopping = true);
Console.WriteLine(worker.Stopping);
}
}
public sealed class Worker { public volatile bool Stopping; }
์ 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)
{
State state = new();
state.Publish();
Console.WriteLine(state.IsReady);
}
}
public sealed class State { private volatile bool ready; public bool IsReady => ready; public void Publish() { ready = true; } }
๊ณต์ ์ถ์ฒ: Microsoft ํ์ต.