Repository navigation
EN CSharp Conditions
Codex edited this page Oct 11, 2026
·
2 revisions
Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
if requires a Boolean expression. Compare numeric game-command results according to each command’s contract, such as result != 0. A zero value does not mean failure for every command.
Save this example separately as Example.cs. Run it independently of the other examples on this page.
Example.cs:
// PROJECT-EXAMPLE
int health = 80;
if (health < 50) System.Console.WriteLine("Low");
else System.Console.WriteLine("Ready");Result:
Ready
int hp = UO.GetHP();
if (hp > 50)
{
UO.Print("High HP");
}
else if (hp > 0)
{
UO.Print("HP is available");
}
else
{
UO.Print("Check character state");
}The switch-operator selects the branch with case, when and default. switch-expression returns a value. Branches can use type, property, and range templates.
int distance = 3;
string label = distance switch
{
0 => "here",
<= 2 => "near",
< 10 => "reachable area",
_ => "far"
};
UO.Print(label);Official documentation: Conditions and switch - Microsoft Learn.
ClassicUO — Bad Newbie & C# Scripts IDE