Repository navigation
ZH TW CSharp Members
Codex edited this page Oct 11, 2026
·
2 revisions
Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
public、private、protected、internal、protected internal 和 private protected 指定可用性。 static指類型,readonly限製字段條目,const指定常數。此屬性使用get、set或init;索引器透過[]提供存取。
請將此範例另存為 Example.cs,並與本頁其他範例分開執行。
Example.cs:
// PROJECT-EXAMPLE
var item = new Item();
item.Count = 7;
System.Console.WriteLine(item.Count);
class Item { public int Count { get; set; } }結果:
7
sealed class Config
{
private int delay = 100;
public string Name { get; init; } = "default";
public int Delay
{
get => delay;
set => delay = Math.Clamp(value, 0, 5000);
}
}
var config = new Config { Name = "Gather", Delay = 150 };
await WaitAsync(config.Delay);
UO.Print(config.Name);sealed class Counters
{
private readonly Dictionary<string, int> values = new();
public int this[string name]
{
get => values.TryGetValue(name, out int value) ? value : 0;
set => values[name] = value;
}
}
var counters = new Counters();
counters["items"] = 3;
UO.Print(counters["items"].ToString());required 要求在建立物件時填入成員。物件和集合初始值設定項不會取代對有效遊戲值的檢查。部分類型partial在編譯單一專案時組合多個宣告。
ClassicUO — Bad Newbie & C# Scripts IDE