System
Akkustand, App-Exit und libnx-Systemfunktionen.
Akkustand
BatteryInfo battery = System.GetBattery();
Graphics.DrawText(10, 10,
$"Akku: {battery.percent}%", Color.White, 1);
if (battery.charging)
Graphics.DrawText(10, 30, "Lädt...", Color.Green, 1);
if (!battery.connected && battery.percent < 20)
Graphics.DrawText(10, 50, "Wenig Akku!", Color.Red, 1);| Feld | Typ | Beschreibung |
|---|---|---|
| percent | int | Ladezustand 0–100 |
| charging | bool | true wenn geladen wird |
| connected | bool | true wenn Ladegerät angesteckt |
App beenden
// Sauber beenden (Standard)
if (Input.IsDown(NpadButton.Plus))
Environment.Exit(0);
// Mit Fehlercode
Environment.Exit(1); Die Plus-Taste (
NpadButton.Plus) ist die Standard-Exit-Taste für Switch-Homebrews. CS2SX beendet die App automatisch bei Plus — du kannst dies aber überschreiben indem du den Aufruf weglässt.Numerische Konstanten
int max = int.MaxValue; // INT_MAX
int min = int.MinValue; // INT_MIN
float fm = float.MaxValue; // FLT_MAX
float fe = float.Epsilon; // FLT_EPSILON
float pi = Math.PI; // (float)M_PI
float e = Math.E; // (float)M_E
float nan = float.NaN; // NAN
float inf = float.PositiveInfinity; // INFINITYKontrollfluss
| Feature | Status |
|---|---|
| if / else if / else | ✓ |
| for, foreach, while, do…while | ✓ |
| foreach über List<T>, Arrays, Dictionary | ✓ |
| switch (Wert und Pattern) | ✓ |
| break, continue, return | ✓ |
| try / catch | ✓ |
| using (mit IDisposable) | ✓ |
| ??, ??=, ?. | ✓ |
| async / await | ✗ |
Pattern Matching
// switch-Expression
string label = value switch { 0 => "zero", 1 => "one", _ => "other" };
// Relationale Pattern
string grade = score switch
{
>= 90 => "A",
>= 70 => "B",
>= 50 => "C",
_ => "F"
};
// is-Pattern
if (obj is Dog d) { d.Bark(); }
if (x is not null) { /* ... */ }
if (n is >= 0 and < 100) { /* ... */ }