KO CSharp Keyword struct - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki
ะฃะบัะฐัะฝััะบะฐ ยท ะ ัััะบะธะน ยท English ยท Deutsch ยท Franรงais ยท Italiano ยท Espaรฑol ยท ็น้ซไธญๆ ยท ๆฅๆฌ่ช ยท ํ๊ตญ์ด
C#: struct
ํธ๋๋ถ C# ยท ์ค์ฉ ๊ฐ์ด๋
๊ฐ ์ ์ธ type: ํ ๋น์ด ๊ฐ์ ๋ณต์ฌํฉ๋๋ค. ์์ ๋ถ๋ณ ๊ตฌ์กฐ๋ ์ขํ์ ๊ฒฐ๊ณผ์ ํธ๋ฆฌํฉ๋๋ค.
๊ฐ๋จํ ์์ (Example.cs)
์ด ์์ ๋ฅผ Example.cs๋ก ๋ฐ๋ก ์ ์ฅํ๊ณ ์ด ํ์ด์ง์ ๋ค๋ฅธ ์์ ์ ๋
๋ฆฝ์ ์ผ๋ก ์คํํ์ธ์.
Example.cs:
// PROJECT-EXAMPLE
Point original = new() { X = 2 };
Point copy = original;
copy.X = 9;
System.Console.WriteLine($"{original.X}:{copy.X}");
struct Point { public int X; }
๊ฒฐ๊ณผ:
2:9
ํต์ฌ๋ก
struct Name { ... } / readonly struct Name { ... }
์์ 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)
{
Point first = new(2, 3);
Point copy = first;
copy.X = 9;
Console.WriteLine($"{first.X}:{copy.X}");
}
}
public struct Point(int x, int y) { public int X = x; public int Y = y; }
์ 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)
{
Position position = new(2, 4);
Console.WriteLine(position.X + position.Y);
}
}
public readonly struct Position(int x, int y) { public int X { get; } = x; public int Y { get; } = y; }
๊ณต์ ์ถ์ฒ: Microsoft ํ์ต.