Skip to content

KO CSharp Classes

Codex edited this page Oct 11, 2026 · 2 revisions

Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어

클래스, 객체 및 생성자

설명서 C# · 예시 UO

클래스는 객체의 상태와 동작을 설명합니다. new는 인스턴스를 생성하고, 생성자는 초기 상태를 설정하고, 필드는 데이터를 저장하고, 속성은 액세스를 제어하고, 메서드는 작업을 수행합니다. this은 현재 인스턴스를 나타냅니다.

간단한 예제 (Example.cs)

이 예제를 Example.cs로 따로 저장하고 이 페이지의 다른 예제와 독립적으로 실행하세요.

Example.cs:

// PROJECT-EXAMPLE
var player = new Player();
System.Console.WriteLine(player.Name);
class Player { public string Name = "Archer"; }

결과:

Archer
sealed class Report
{
    public string Name { get; }
    public int Count { get; private set; }
    public Report(string name) => Name = name;
    public void Add() => Count++;
    public override string ToString() => $"{Name}: {Count}";
}

var report = new Report("Attempts");
report.Add();
report.Add();
UO.Print(report.ToString());

일반 .cs 프로젝트에서는 유형을 파일로 분리해 두는 것이 편리합니다. .csx은 자체 유형을 선언할 수 있지만 클래스 내부의 코드는 UO 객체를 자동으로 가져오지 않습니다. API 또는 원하는 대리자를 명시적으로 전달합니다.

sealed class MessageWriter
{
    private readonly Action<string> write;
    public MessageWriter(Action<string> write) => this.write = write;
    public void Send(string text) => write(text);
}

var writer = new MessageWriter(text => UO.Print(text));
writer.Send("A class uses the current session API");

공식 문서: 클래스, 개체 및 생성자 - Microsoft Learn.

Clone this wiki locally