KO CSharp Keyword sizeof - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki
ะฃะบัะฐัะฝััะบะฐ ยท ะ ัััะบะธะน ยท English ยท Deutsch ยท Franรงais ยท Italiano ยท Espaรฑol ยท ็น้ซไธญๆ ยท ๆฅๆฌ่ช ยท ํ๊ตญ์ด
C#: sizeof
ํธ๋๋ถ C# ยท ์ค์ฉ ๊ฐ์ด๋
๊ด๋ฆฌ๋์ง ์๋ ์ ํ์ ํฌ๊ธฐ๋ฅผ ๋ฐ์ดํธ ๋จ์๋ก ๋ฐํํฉ๋๋ค. ํน์ ๊ธฐ๋ณธ ์์์๋ ์์ ํ์ง ์์ ์ปจํ ์คํธ๊ฐ ํ์ํ์ง ์์ต๋๋ค.
๊ฐ๋จํ ์์ (Example.cs)
์ด ์์ ๋ฅผ Example.cs๋ก ๋ฐ๋ก ์ ์ฅํ๊ณ ์ด ํ์ด์ง์ ๋ค๋ฅธ ์์ ์ ๋
๋ฆฝ์ ์ผ๋ก ์คํํ์ธ์.
Example.cs:
// PROJECT-EXAMPLE
System.Console.WriteLine(sizeof(int));
๊ฒฐ๊ณผ:
4
ํต์ฌ๋ก
sizeof(Type)
.csproj์์ true๋ฅผ ์ค์ ํ์ธ์. ๊ด๋ฆฌ๋๋ ๋ฐ์ดํฐ์ ๊ฒฝ์ฐ ์ผ๋ฐ์ ์ผ๋ก ์์ ํฌ์ธํฐ ์์ด Span๋ฅผ ํตํด ์์ ํ๋ ๊ฒ์ด ๋ ์ฝ์ต๋๋ค.
์์ 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)
{
unsafe { int* values = stackalloc int[2]; values[0] = 3; values[1] = 7; Console.WriteLine(values[0] + values[1]); Console.WriteLine(sizeof(int)); }
}
}
์ 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)
{
int[] values = [2, 4, 6];
unsafe { fixed (int* pointer = values) { pointer[1] = 9; Console.WriteLine(*(pointer + 1)); Console.WriteLine(sizeof(long)); } }
Console.WriteLine(values[1]);
}
}
๊ณต์ ์ถ์ฒ: Microsoft ํ์ต.