Repository navigation
JA CSharp Variables
Codex edited this page Oct 11, 2026
·
2 revisions
Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
変数は使用する前に宣言し、読み取る前に値を指定する必要があります。ローカル名はそのブロック内に表示されます。パラメータ - メソッド内。 const はコンパイル時の値を指定し、readonly はフィールドの割り当てをコンストラクターまたは宣言に制限します。
この例を Example.cs として別に保存し、このページの他の例とは独立して実行してください。
Example.cs:
// PROJECT-EXAMPLE
int count = 2;
count += 3;
const int Limit = 10;
System.Console.WriteLine($"{count}/{Limit}");結果:
5/10
const int MaximumAttempts = 3;
int completed = 0;
for (int attempt = 0; attempt < MaximumAttempts; attempt++)
{
completed++;
}
UO.Print($"Completed: {completed}");静的フィールドは型に属し、1 回の実行中ではその型のインスタンス間で共有されます。.csx、.cs、.csproj の各実行はユーザー定義型とその静的フィールドを分離し、コンパイル結果のキャッシュは実行間でこれらのフィールドを保持しません。共有される .NET とホストのライブラリの静的データは共有されたままなので、特定のキャラクターのデータを保存しないでください。
sealed class Options
{
public readonly int Delay;
public Options(int delay) => Delay = delay;
}
var options = new Options(100);
await WaitAsync(options.Delay);公式ドキュメント: 変数、定数、およびスコープ - Microsoft Learn。
ClassicUO — Bad Newbie & C# Scripts IDE