KO CSharp Keyword field - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki
ะฃะบัะฐัะฝััะบะฐ ยท ะ ัััะบะธะน ยท English ยท Deutsch ยท Franรงais ยท Italiano ยท Espaรฑol ยท ็น้ซไธญๆ ยท ๆฅๆฌ่ช ยท ํ๊ตญ์ด
C#: field
ํธ๋๋ถ C# ยท ์ค์ฉ ๊ฐ์ด๋
์ ๊ทผ์ ๋ด๋ถ์ ์๋์ผ๋ก ์์ฑ๋ ์์ฑ ํ๋๋ฅผ ์ฐธ์กฐํฉ๋๋ค. ์๋ ์ ์ฅ๊ณผ ํ์ธ์ ๊ฒฐํฉํ ์ ์์ต๋๋ค.
๊ฐ๋จํ ์์ (Example.cs)
์ด ์์ ๋ฅผ 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 ์๋ณ์๋ ๋์ผํ ์ด๋ฆ์ ๊ฐ์ง ์์ฒด ๋ฉค๋ฒ๋ฅผ ์ฐธ์กฐํ ์ ์์ต๋๋ค.
์์ 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)
{
Meter meter = new() { Count = -3 };
Console.WriteLine(meter.Count);
}
}
public class Meter { public int Count { get; set => field = Math.Max(0, value); } }
์ 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)
{
Profile profile = new() { Name = " archer " };
Console.WriteLine(profile.Name);
}
}
public class Profile { public string Name { get => field ?? ""; set => field = value.Trim(); } }
๊ณต์ ์ถ์ฒ: Microsoft ํ์ต.