Skip to content

KO CSharp Keyword closed

Codex edited this page Oct 11, 2026 · 2 revisions

Українська · Русский · 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 학습.

Clone this wiki locally