Hallo zu dieser späten Stunde.
Ich habe gerade folgende Struktur erstellt:
Im Codeditor wird mir kein Fehler angezeigt, beim Kompilieren erhalte ich jedoch in den Zeilen 12 und 19 diesen Fehler:
Wer dreht hier durch, ich oder Visual Studio? Wo soll ich denn da ne Fixed-Anweisung verwenden?
Edit: es scheint so, als ob das hier funktionieren würde:
Warum ist das so? Warum muss ich das nochmal anpinnen?
Ich habe gerade folgende Struktur erstellt:
C#-Quellcode
- public unsafe struct Matrix2x3
- {
- fixed float values[6];
- public float this[int x, int y]
- {
- get
- {
- if (x < 0 || x > 1 || y < 0 || y > 2)
- throw new IndexOutOfRangeException();
- return values[x * 3 + y];
- }
- set
- {
- if (x < 0 || x > 1 || y < 0 || y > 2)
- throw new IndexOutOfRangeException();
- values[x * 3 + y] = value;
- }
- }
- //...
Edit: es scheint so, als ob das hier funktionieren würde:
C#-Quellcode
- public unsafe struct Matrix2x3
- {
- fixed float values[6];
- public float this[int x, int y]
- {
- get
- {
- if (x < 0 || x > 1 || y < 0 || y > 2)
- throw new IndexOutOfRangeException();
- fixed (float* p = values)
- {
- return p[x * 3 + y];
- }
- }
- set
- {
- if (x < 0 || x > 1 || y < 0 || y > 2)
- throw new IndexOutOfRangeException();
- fixed (float* p = values)
- {
- p[x * 3 + y] = value;
- }
- }
- }
- }
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Artentus“ ()