Typen & Collections
Unterstützte C#-Typen, Collections, Nullable-Typen, Mathematik und Zufallszahlen.
Primitive Typen
| C# | C-Mapping | Hinweis |
|---|---|---|
| int | int | |
| uint | unsigned int | |
| long | long long | |
| float | float | |
| bool | int | 0 = false, 1 = true |
| string | const char* | Puffer 512 Bytes |
| u8 / u16 / u32 / u64 | u8/u16/u32/u64 | libnx-Typen |
| s8 / s16 / s32 / s64 | s8/s16/s32/s64 | libnx-Typen |
List<T>
var scores = new List<int>();
scores.Add(100);
scores.Add(200);
scores.Remove(0); // Index entfernen
scores.Contains(100); // true
scores.Sort();
scores.Reverse();
int val = scores.Get(0); // Index-Zugriff
// foreach
for (int i = 0; i < scores.Count; i++)
Graphics.DrawText(10, 10 + i * 20, scores.Get(i).ToString(), Color.White, 1);Unterstützte Typen: List<int>, List<float>, List<string>, List<u8/u16/u32/u64>
Dictionary<K,V>
var map = new Dictionary<string, int>();
map.Add("Alice", 100);
map.Add("Bob", 80);
if (map.ContainsKey("Alice"))
{
if (map.TryGetValue("Alice", out var score))
Graphics.DrawText(10, 10, $"Alice: {score}", Color.White, 1);
}
map.Remove("Bob");
// foreach über alle Einträge
foreach (var kvp in map)
Graphics.DrawText(10, y, $"{kvp.Key}: {kvp.Value}", Color.White, 1);StringBuilder
var sb = new StringBuilder(256);
sb.Append("Score: ");
sb.Append(100);
sb.AppendLine(" Punkte");
sb.Replace("Score", "Punkte");
string result = sb.ToString();
sb.Clear();Nullable-Typen
int? x = null;
int? y = 42;
bool has = x.HasValue; // false
int val = y.Value; // 42
int result = x ?? 0; // 0 (Null-Coalescing)
y?.ToString(); // "42" oder nullMathematik
| C# | C-Output |
|---|---|
| Math.Abs(x) | abs(x) |
| Math.Min(a, b) / Max | MIN(a,b) / MAX(a,b) |
| Math.Clamp(v, lo, hi) | CLAMP(v,lo,hi) |
| Math.Sqrt(x) | sqrtf(x) |
| Math.Sin/Cos/Tan(x) | sinf/cosf/tanf(x) |
| Math.Atan2(y, x) | atan2f(y,x) |
| Math.Floor/Ceiling/Round(x) | floorf/ceilf/roundf(x) |
| Math.Pow(x, y) | powf(x,y) |
| Math.Sign(x) | CS2SX_Sign(x) |
| Math.PI | (float)M_PI |
Zufallszahlen
int n1 = Random.Shared.Next(0, 100); // 0–99
int n2 = Random.Shared.Next(50); // 0–49
float f = Random.Shared.NextSingle(); // 0.0–1.0
// Instanz
var rng = new Random();
int dice = rng.Next(1, 7); // WürfelwurfString-Methoden
string s = " Hello World ";
s.Trim(); // "Hello World"
s.ToUpper(); // " HELLO WORLD "
s.Contains("World"); // true
s.StartsWith(" Hello"); // true
s.Replace("Hello", "Hi"); // " Hi World "
s.Substring(2, 5); // "Hello"
s.IndexOf("World"); // 8
s.Split(" "); // List<string>
string.Join(", ", myList); // "a, b, c"
// Parsing
int.Parse("42"); // 42
int.TryParse("abc", out var n); // false
float.Parse("3.14"); // 3.14f