KO CSharp Keyword safe - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki
ะฃะบัะฐัะฝััะบะฐ ยท ะ ัััะบะธะน ยท English ยท Deutsch ยท Franรงais ยท Italiano ยท Espaรฑol ยท ็น้ซไธญๆ ยท ๆฅๆฌ่ช ยท ํ๊ตญ์ด
C#: safe
ํธ๋๋ถ C# ยท ์ค์ฉ ๊ฐ์ด๋
์ ๋ฐ์ดํธ๋ ๋ฉ๋ชจ๋ฆฌ ์์ ๋ชจ๋ธ์ ๋ฏธ๋ฆฌ๋ณด๊ธฐ ์์ ์: ์์ฑ์๋ ํธ์ถ์์ ์์ ํ์ง ์์ ์ปจํ ์คํธ๋ฅผ ์๊ตฌํ์ง ์๋ ๊ฒ์ผ๋ก ์ ์ธ์ ๋ช ์์ ์ผ๋ก ํ์ํฉ๋๋ค.
๊ฐ๋จํ ์์ (Example.cs)
์ด ์์ ๋ฅผ Example.cs๋ก ๋ฐ๋ก ์ ์ฅํ๊ณ ์ด ํ์ด์ง์ ๋ค๋ฅธ ์์ ์ ๋
๋ฆฝ์ ์ผ๋ก ์คํํ์ธ์.
Example.cs:
// PROJECT-EXAMPLE
class ManagedValue { public int Count { get; set; } }
์ด ์งง์ ์์ ๋ C# 14๋ฅผ ์ฌ์ฉํฉ๋๋ค. ์ฌ๊ธฐ์์ ์ง์๋์ง ์๋ ๋ฏธ๋ฆฌ ๋ณด๊ธฐ ๊ตฌ๋ฌธ safe๋ฅผ ๊ตฌํํ์ง ์์ต๋๋ค.
ํต์ฌ๋ก
public static safe extern int Method();
C# 15 / .NET 11์ ๋ฏธ๋ฆฌ๋ณด๊ธฐ์ ๋๋ค. ๊ณต์ ๊ท์น์์๋ LangVersion=๋ฏธ๋ฆฌ๋ณด๊ธฐ๋ฅผ ์๊ตฌํ๊ณ ํด๋น ์ ํ๋ฆฌ์ผ์ด์ ์ ๋ํด ์ ๋ฐ์ดํธ๋ ๋ฉ๋ชจ๋ฆฌ ์์ ๊ท์น์ ๋ณ๋๋ก ํ์ฑํํด์ผ ํฉ๋๋ค. ํ์ฌ C# 14์์๋ ์ด๋ฌํ ์ ์ธ์ ์ง์ํ์ง ์์ต๋๋ค.
์ํ: ๋ฏธ๋ฆฌ๋ณด๊ธฐ; ํ์ฌ ๊ตฌ์ฑ C# 14 / .NET 10๋ ์ด๋ฌํ ์๋ฅผ ์ง์ํ์ง ์์ต๋๋ค.
์์ 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)
{
Console.WriteLine(Native.GetCurrentProcessId());
}
}
public static class Native { [DllImport("kernel32.dll")] public static safe extern uint GetCurrentProcessId(); }
์ 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)
{
Union value = new() { Integer = 1065353216 };
Console.WriteLine(value.Real);
}
}
[StructLayout(LayoutKind.Explicit)] public struct Union { [FieldOffset(0)] public safe int Integer; [FieldOffset(0)] public safe float Real; }
๊ณต์ ์ถ์ฒ: Microsoft ํ์ต.