Repository navigation
JA 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 は、単一のプロジェクトをコンパイルするときに複数の宣言を結合します。
公式ドキュメント: フィールド、プロパティ、インデクサー、および修飾子 - Microsoft Learn。
ClassicUO — Bad Newbie & C# Scripts IDE