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 ํ•™์Šต.