KO CSharp Keyword closed - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki

ะฃะบั€ะฐั—ะฝััŒะบะฐ ยท ะ ัƒััะบะธะน ยท English ยท Deutsch ยท Franรงais ยท Italiano ยท Espaรฑol ยท ็น้ซ”ไธญๆ–‡ ยท ๆ—ฅๆœฌ่ชž ยท ํ•œ๊ตญ์–ด

C#: closed

ํ•ธ๋“œ๋ถ C# ยท ์‹ค์šฉ ๊ฐ€์ด๋“œ

ํ์‡„ ๊ณ„์ธต ๋ฏธ๋ฆฌ๋ณด๊ธฐ ์ˆ˜์ •์ž: ์ง๊ณ„ ํ•˜์œ„ ํ•ญ๋ชฉ์€ ๋™์ผํ•œ ์–ด์…ˆ๋ธ”๋ฆฌ์— ์†ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ปดํŒŒ์ผ๋Ÿฌ๋Š” ์ด๋Ÿฌํ•œ ํ•˜์œ„ ํ•ญ๋ชฉ์œผ๋กœ ์ „ํ™˜์˜ ์™„์ „์„ฑ์„ ๋ถ„์„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๊ฐ„๋‹จํ•œ ์˜ˆ์ œ (Example.cs)

์ด ์˜ˆ์ œ๋ฅผ Example.cs๋กœ ๋”ฐ๋กœ ์ €์žฅํ•˜๊ณ  ์ด ํŽ˜์ด์ง€์˜ ๋‹ค๋ฅธ ์˜ˆ์ œ์™€ ๋…๋ฆฝ์ ์œผ๋กœ ์‹คํ–‰ํ•˜์„ธ์š”.

Example.cs:

// PROJECT-EXAMPLE
sealed class Finished { }

์ด ์งง์€ ์˜ˆ์ œ๋Š” C# 14๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์—์„œ ์ง€์›๋˜์ง€ ์•Š๋Š” ๋ฏธ๋ฆฌ ๋ณด๊ธฐ ๊ตฌ๋ฌธ closed๋ฅผ ๊ตฌํ˜„ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

ํ†ต์‚ฌ๋ก 

public closed class Base { ... }

๊ณต์‹ ๋””๋ ‰ํ† ๋ฆฌ๋Š” C# 15๋กœ ํ์‡„๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ํ˜„์žฌ C# 14 / .NET 10์—์„œ๋Š” ์ด๋Ÿฌํ•œ ์˜ˆ๋ฅผ ํ—ˆ์šฉํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ํ˜ธํ™˜๋˜๋Š” ๋ฏธ๋ฆฌ๋ณด๊ธฐ ์ปดํŒŒ์ผ๋Ÿฌ์™€ ํ•ด๋‹น ๋Ÿฐํƒ€์ž„ ํ”Œ๋žซํผ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ์ด๋Š” ์ง€์› ํ™œ์„ฑํ™” ๋ช…๋ น์ด ์•„๋‹Œ ํ–ฅํ›„ ๊ธฐ๋Šฅ์— ๋Œ€ํ•œ ๊ฐœ์š”์ž…๋‹ˆ๋‹ค.

์ƒํƒœ: ๋ฏธ๋ฆฌ๋ณด๊ธฐ; ํ˜„์žฌ ๊ตฌ์„ฑ 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)
    {
        Status status = new Ready();
        Console.WriteLine(status switch { Ready => "ready", Busy => "busy" });
    }
}
public closed record Status;
public sealed record Ready : Status;
public sealed record Busy : Status;

์˜ˆ 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)
    {
        Shape shape = new Circle(3);
        Console.WriteLine(shape switch { Circle(var radius) => radius * radius, Box(var width) => width * width });
    }
}
public closed record Shape;
public sealed record Circle(int Radius) : Shape;
public sealed record Box(int Width) : Shape;

๊ณต์‹ ์ถœ์ฒ˜: Microsoft ํ•™์Šต.