Repository navigation
KO CSharp Keyword field
Codex edited this page Oct 11, 2026
·
2 revisions
Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
접근자 내부에 자동으로 생성된 속성 필드를 참조합니다. 자동 저장과 확인을 결합할 수 있습니다.
이 예제를 Example.cs로 따로 저장하고 이 페이지의 다른 예제와 독립적으로 실행하세요.
Example.cs:
// PROJECT-EXAMPLE
var item = new Item();
item.Count = -2;
System.Console.WriteLine(item.Count);
class Item { public int Count { get; set => field = System.Math.Max(0, value); } }결과:
0
public int Count { get; set => field = Math.Max(0, value); }구문 C# 14. @field 식별자는 동일한 이름을 가진 자체 멤버를 참조할 수 있습니다.
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)
{
Meter meter = new() { Count = -3 };
Console.WriteLine(meter.Count);
}
}
public class Meter { public int Count { get; set => field = Math.Max(0, value); } }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)
{
Profile profile = new() { Name = " archer " };
Console.WriteLine(profile.Name);
}
}
public class Profile { public string Name { get => field ?? ""; set => field = value.Trim(); } }공식 출처: Microsoft 학습.
ClassicUO — Bad Newbie & C# Scripts IDE