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