KO CSharp Keyword record - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki
ะฃะบัะฐัะฝััะบะฐ ยท ะ ัััะบะธะน ยท English ยท Deutsch ยท Franรงais ยท Italiano ยท Espaรฑol ยท ็น้ซไธญๆ ยท ๆฅๆฌ่ช ยท ํ๊ตญ์ด
C#: record
ํธ๋๋ถ C# ยท ์ค์ฉ ๊ฐ์ด๋
๊ฐ, ํ์ ๋ฐ ์ง์์ ๊ธฐ์ค์ผ๋ก ์์ฑ๋ ๋น๊ต๋ฅผ ์ฌ์ฉํ์ฌ ์ ํ์ ์ ์ธํฉ๋๋ค. ๋ ์ฝ๋ ํด๋์ค - ์ฐธ์กฐ; ๋ ์ฝ๋ ๊ตฌ์กฐ์ฒด โ ๊ฐ type.
๊ฐ๋จํ ์์ (Example.cs)
์ด ์์ ๋ฅผ Example.cs๋ก ๋ฐ๋ก ์ ์ฅํ๊ณ ์ด ํ์ด์ง์ ๋ค๋ฅธ ์์ ์ ๋
๋ฆฝ์ ์ผ๋ก ์คํํ์ธ์.
Example.cs:
// PROJECT-EXAMPLE
var first = new Item("ore");
var second = new Item("ore");
System.Console.WriteLine(first == second);
record Item(string Name);
๊ฒฐ๊ณผ:
True
ํต์ฌ๋ก
record Person(string Name); / readonly record struct Point(int X, int Y);
์์ 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)
{
Person first = new("Archer");
Person second = new("Archer");
Console.WriteLine(first == second);
}
}
public record Person(string Name);
์ 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)
{
Point start = new(2, 3);
Point next = start with { X = 8 };
Console.WriteLine($"{start} -> {next}");
}
}
public readonly record struct Point(int X, int Y);
๊ณต์ ์ถ์ฒ: Microsoft ํ์ต.